Last active
October 29, 2024 18:28
-
-
Save wahengchang/108ca55981f6600c252ad0cb9d4c518f to your computer and use it in GitHub Desktop.
Unit test, mocking components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ShareCom} from '../somewhere/ShareCom' | |
jest.mock('../somewhere/UserCom', () => ()=> <div id="mockUserCom">mockUserCom</div>) | |
jest.mock('installComponent', () => ({ | |
InstallCom: 'mockInstallCom' | |
})) | |
describe('ShareCom', () => { | |
it('should return correct component', () => { | |
const wrapper = mount( | |
<ShareCom | |
something={something} | |
/> | |
) | |
expect(wrapper.find('mockInstallCom').length).toEqual(1) | |
expect(wrapper.find('#mockUserCom').length).toEqual(1) | |
}) | |
}) |
Great!
Great! works for me ))
👍 Thank you! Works for me
i whant understand when i write this mock :const mockValidateObject = jest.fn(({ entityName, object, configData }) => {
if (entityName instanceof String) {
return true;
} else {
return false;
}
})
jest.mock('../../../modules/validation', () => {
return {
validateObject: mockValidateObject,
}
})and when i write this mock:jest.mock('../../../modules/validation', () => ({
validateObject: (() => {
return false
})
}))What does it depend on??
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working