Jest snapshot test failed with TypeError: Cannot read property 'extend' of undefined
See original GitHub issueBelow is the sample code.
Filename: TestComponent.svelte
<script>
import * as dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
dayjs.extend(relativeTime)
dayjs('1999-01-01').fromNow()
</script>
<div>
Hello World !!!
</div>
Filename: TestComponent.test.js
import { render } from '@testing-library/svelte'
import TestComponent from './TestComponent.svelte'
describe('Render component', () => {
it('should render component correctly', () => {
const { component } = render(TestComponent)
expect(component).toMatchSnapshot()
})
})
Information dayjs : 1.10.4
** Error **

Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
jestjs - Jest 28: createJestExpect - TypeError: Cannot read ...
Test suite failed to run TypeError: Cannot read properties of undefined (reading 'extend') at createJestExpect ...
Read more >cannot read property 'testenvironmentoptions' of undefined
The "Cannot read property 'testEnvironmentOptions' of undefined" error occurs when a property is read or a function is called on an undefined variable...
Read more >Expect · Jest
If you mix them up, your tests will still work, but the error messages on failing tests will look strange. expect.extend(matchers) #. You...
Read more >API Reference
import { assert, test } from 'vitest' test.skip('skipped test', () => { // Test skipped, no error assert.equal(Math.sqrt(4), 3) }) ...
Read more >Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes. Just had wrong import. For some reason it worked on application level both ways, but on test level it didn’t. Once the import was changed and was same on both sides it was working as intended. At the moment, I have following imports:
Also I am calling now
dayjs.extend(...);inside constructor. This is my case, other people requirements can be different.Oh, hmm. Well, I’ve done basically the same thing as you, but in Angular, and get no error.