Created
April 28, 2023 18:48
-
-
Save epreston/19d4bd07e46ffcfba24e75aadf7435e1 to your computer and use it in GitHub Desktop.
vitest - generic test file format example
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 { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; | |
// --------------------------------------------------------- | |
// import { itemsToMock } from '../src/testDependency.js'; | |
// --------------------------------------------------------- | |
// vi.mock('../src/testDependency.js'); | |
// --------------------------------------------------------- | |
// import { itemBeingTested } from '../src/testTarget.js'; | |
// --------------------------------------------------------- | |
const props = { | |
foo: vi.fn(), | |
bar: { | |
baz: true, | |
}, | |
}; | |
// --------------------------------------------------------- | |
describe('Object', () => { | |
let instance; | |
beforeAll(() => { | |
instance = Object.assign({}, props); | |
}); | |
// beforeEach(() => { | |
// instance = Object.assign({}, props); | |
// }); | |
it('should expose an object', () => { | |
expect(instance).toBeDefined(); | |
expect(instance).toBeInstanceOf(Object); | |
}); | |
it('should have the expected properties', () => { | |
expect(instance).toHaveProperty('bar'); | |
}); | |
it('should have a method foo()', () => { | |
// instance.foo(); | |
expect(instance.foo).toBeDefined(); | |
instance.foo(); | |
expect(instance.foo).toHaveBeenCalled(); | |
}); | |
it('should load and configure the object correctly', () => { | |
expect(instance).toMatchSnapshot(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment