Skip to content

Commit

Permalink
test(smooth-corners): add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sungik-choi committed Sep 22, 2023
1 parent aeff39b commit cbb1d4e
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import SmoothCornersFeature from './SmoothCornersFeature'

describe('SmoothCornersFeature', () => {
let addModule: jest.Mock

beforeEach(() => {
addModule = jest.fn(() => Promise.resolve())

Object.defineProperty(global, 'URL', {
value: {
createObjectURL: jest.fn(),
},
})

Object.defineProperty(global, 'CSS', {
value: {
paintWorklet: { addModule },
},
})
})

it('If the global objects are the same, activate should only be executed once.', async () => {
await SmoothCornersFeature.activate(globalThis)
await SmoothCornersFeature.activate(globalThis)
expect(addModule).toHaveBeenCalledTimes(1)
})

it('If the global object has changed, activate should be executed again.', async () => {
await SmoothCornersFeature.activate(globalThis)
expect(addModule).toHaveBeenCalledTimes(0)
await SmoothCornersFeature.activate({ ...globalThis })
expect(addModule).toHaveBeenCalledTimes(1)
})
})

0 comments on commit cbb1d4e

Please sign in to comment.