Skip to content

Commit

Permalink
Update jest tests that have restored spyOn mocks
Browse files Browse the repository at this point in the history
In the latest Jest, jest.restoreAllMocks() seems to restore also other
kind of mocks than jest.spyOn().
  • Loading branch information
yhatt committed Feb 18, 2023
1 parent 73a155d commit 4549f74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions test/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { applyCustomElements } from '../src/custom-elements/browser'

const polyfillCleanup = jest.fn()

jest.mock('@marp-team/marpit-svg-polyfill', () => ({
observe: jest.fn(() => polyfillCleanup),
}))

jest.mock('@marp-team/marpit-svg-polyfill')
jest.mock('../src/custom-elements/browser')

beforeEach(() => jest.clearAllMocks())
beforeEach(() => {
jest.clearAllMocks()
;(observe as jest.Mock).mockReturnValue(polyfillCleanup)
})
afterEach(() => jest.restoreAllMocks())

describe('Browser script', () => {
Expand Down
7 changes: 6 additions & 1 deletion test/custom-elements/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ beforeAll(() => {
})

afterEach(() => {
jest.restoreAllMocks()
window[browser.marpCustomElementsRegisteredSymbol] = false

// Reset custom elements defined in JSDOM
Expand Down Expand Up @@ -100,6 +99,12 @@ describe('The hydration script for custom elements', () => {
.mockReturnValue(false)
})

afterEach(() => {
;(
browser.isSupportedCustomizedBuiltInElements as jest.Mock
).mockRestore()
})

it('replaces all of elements that are using "is" attribute to the standalone custom element', () => {
document.body.innerHTML = Object.keys(elements)
.map((elm) => `<${elm} is="marp-${elm}"></${elm}>`)
Expand Down

0 comments on commit 4549f74

Please sign in to comment.