mapModuleコンポーネントをインポートしてエクスポートする場所があります。
import ComponentName from '../components/ComponentName';
export default {
  name: ComponentName,
};
mapModule正しくエクスポートされたキー、値があり、それらがnullまたは未定義ではないことをテストするにはどうすればよいですか?
回答:
jestのバージョン23.3.0では、
expect(string).toMatch(string) 
文字列が必要です。
使用する:
const expected = { name:'component name' }
const actual = { name: 'component name', type: 'form' }
expect(actual).toMatchObject(expected)
結果はテストに合格しています
次のいずれかを使用できます。
toEqualとtoMatchObjectは、オブジェクトのテンプレートマッチャーです。
let Obj = {name: 'component name', id: 2};
expect(oneObj).toEqual({name: 'component name'}) // false, should be exactly equal all Obj keys and values  
expect(oneObj).toMatchObject({name: 'component name'}) // true
またはtoHavePropertyを簡単に使用できます:
let Obj = {name: 'component name'};
expect(oneObj).toHaveProperty('name') // true
expect(oneObj).toHaveProperty('name', 'component name') // true
    .toMatchObject「JavaScriptオブジェクトがオブジェクトのプロパティのサブセットと一致すること」をチェックすることに注意してください。したがって、意図しないアサーションが含まれる可能性があります。
expect({ a: 1, b: 2 }).toMatchObject({ a: 1 }); // pass
オブジェクトを正確に一致させたい場合は、を使用する必要が.toStrictEqualありますjest 23。
expect({ a: 1, b: 2 }).toStrictEqual({ a: 1 }); // fail
    
toMatch必要がありtoMatchObjectます