-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mrc-5952 vitest pt 1 #219
Mrc-5952 vitest pt 1 #219
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! It's hard to tell from CI how these front end tests are doing because it runs the back end tests first - which also fail. so it never gets as far as the front end ones. Might be worth swapping that order round for now?
vi.mock("plotly.js-basic-dist-min", () => { | ||
return { | ||
default: undefined, | ||
update: undefined | ||
} | ||
}); | ||
vi.mock("../../../../src/components/help/MarkdownItImport.ts", () => { | ||
class MarkDownItClass { | ||
constructor() { | ||
return { | ||
use: vi.fn().mockReturnValue({ | ||
renderer: { rules: {} }, | ||
render: vi.fn() | ||
}) | ||
} | ||
} | ||
}; | ||
return { | ||
default: { | ||
default: MarkDownItClass | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If some of these bits are going to pop up several times, I wonder if it would be worth importing them from a shared module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats a good idea im not sure if you actually can even extract out vi.mocks, they seem to care about hoisting and not capturing stuff from the env and so on but i think there must be some functionality in vitest! i have made a ticket: https://mrc-ide.myjetbrains.com/youtrack/issue/mrc-5980/vi.mock-in-shared-module will do it in a future pr
i did these PRs after they all started passing, will see it passing fairly soon! |
part 1 for the vitest upgrade, some main changes to be aware of that youll be seeing in the following PRs:
vi.mock
is very similar tojest.mock
but you do have to mock everything the component uses explicitly so if you importupdate
function fromplotly.js-basic-min
then you have to explicitly state it as undefined even if you dont use it in the test soupdate: undefined
vi.mock
and use them later in your file to see how many times theyve been called for example then you must usevi.hoisted
to create your mocked functions and these will be available invi.mock
and the rest of your testsdone
callbacks have been deprecated for a while, so replacingsetTimeout
with await/async