mzgoddard / preact-render-spy

Render preact components with access to the produced virtual dom for testing.
https://www.npmjs.com/package/preact-render-spy
ISC License
178 stars 24 forks source link

TypeError: this.contextRender is not a function when using shallow #91

Open kolnogorov opened 5 years ago

kolnogorov commented 5 years ago

When i run test, it fails with the TypeError: this.contextRender is not a function when using shallow error.

This is my test:

import { h } from 'preact'
import { shallow } from 'preact-render-spy'
import { App } from '../../src/app'

describe('App', () => {
  test('renders', () => {
    const context = shallow(<App />)
    expect(context.find('div').contains(<a>link</a>)).toBeTruthy()
  })
})

This is error i get:

 FAIL  test/src/app.test.js
  App
    ✕ renders (4ms)

  ● App › renders

    TypeError: this.contextRender is not a function

       5 | describe('App', () => {
       6 |   test('renders', () => {
    >  7 |     const context = shallow(<App />)
         |                     ^
       8 |     expect(context.find('div').contains(<a>link</a>)).toBeTruthy()
       9 |   })
      10 | })

      at RenderContext.render (node_modules/preact-render-spy/src/preact-render-spy.js:462:10)
      at deep (node_modules/preact-render-spy/src/preact-render-spy.js:472:76)
      at shallow (node_modules/preact-render-spy/src/preact-render-spy.js:473:25)
      at Object.<anonymous> (test/src/app.test.js:7:21)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.196s
Ran all test suites.
shelacek commented 5 years ago

This error occurs when you use Preact 10 (issue #92). Is this also true in this case?