Skip to content

Commit

Permalink
Updated test for createFacetContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Shenato committed Nov 3, 2022
1 parent c28d96a commit f6ba8f2
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion packages/@react-facet/core/src/createFacetContext.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,33 @@ describe('createFacetContext initial facet', () => {
process.env.NODE_ENV = 'test' // Restore NODE_ENV back to test to not mess with subsequent tests
})

it(`it responds with the same value if you observe it and warns you in a non-production environment`, () => {
it(`it responds with the same value if you observe it and warns you in a non-test environment`, () => {
const consoleLogMock = jest.spyOn(console, 'log').mockImplementation()

const update = jest.fn()
process.env.NODE_ENV = 'development'

staticFacet.observe(update)
expect(update).toHaveBeenCalledTimes(1)
expect(update).toHaveBeenCalledWith(defaultValue)
expect(consoleLogMock).toHaveBeenCalledTimes(1)
expect(consoleLogMock).toHaveBeenCalledWith(
`Accessing a static facet created through createFacetContext, perhaps you're missing a Context Provider? initialValue: `,
JSON.stringify(defaultValue),
)

update.mockClear()
consoleLogMock.mockClear()

process.env.NODE_ENV = 'test'

staticFacet.observe(update)
expect(update).toHaveBeenCalledTimes(1)
expect(update).toHaveBeenCalledWith(defaultValue)
expect(consoleLogMock).toHaveBeenCalledTimes(0)
})

it(`it responds with the same value if you observe it and warns you in a non-production environment once per instance`, () => {
const consoleLogMock = jest.spyOn(console, 'log').mockImplementation()

const update = jest.fn()
Expand All @@ -148,6 +174,14 @@ describe('createFacetContext initial facet', () => {
update.mockClear()
consoleLogMock.mockClear()

staticFacet.observe(update)
expect(update).toHaveBeenCalledTimes(1)
expect(update).toHaveBeenCalledWith(defaultValue)
expect(consoleLogMock).toHaveBeenCalledTimes(0)

update.mockClear()
consoleLogMock.mockClear()

process.env.NODE_ENV = 'test'

staticFacet.observe(update)
Expand Down

0 comments on commit f6ba8f2

Please sign in to comment.