question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

snapshot tests failing with `Cannot read property 'split' of null`

See original GitHub issue

Description

When snapshots do not match a type error is thrown instead of the diff. TypeError: Cannot read property 'split' of null.

Test Source

import React from 'react';
import test from 'ava';
import { render } from 'enzyme';

const TestMe = ({ me }) => (
  <div>
    <p>{me}</p>
  </div>
);

test('renders the component', t => {
  const wrapper = render(<TestMe me='change me' />);
  t.snapshot(wrapper.html());
});

Error Message & Stack Trace

Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
  ✖ renders the component Error thrown in test

  1 test failed [11:04:02]

  renders the component
  /path/to/example.test.js:13

   12:   const wrapper = render(<TestMe me='change us' />);
   13:   t.snapshot(wrapper.html());
   14: });

  Error thrown in test

  Error:

    [TypeError: Cannot read property 'split' of null]

Config

Copy the relevant section from package.json:

{
  "ava": {
    "require": [
      "babel-register",
      "./test-environment.js"
    ],
    "babel": "inherit",
    "files": [
      "**/*.test.js",
      "!node_modules"
    ]
  }
}

Command-Line Arguments

Copy your npm build scripts or the ava command used:

ava --verbose path/to/example.test.js

Relevant Links

https://gist.github.com/pho3nixf1re/4c23d77709ce4ef044ebae7c937940ec

Environment

Node.js v7.10.0
darwin 16.5.0
AVA 0.19.1
npm 4.2.0
yarn v0.23.4

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mmmveggiescommented, Jun 9, 2017

For those who end up here looking for a fix, you can delete the corresponding entry in the __snapshots__/ folder. You lose your snapshot history but it will fix the bug

0reactions
novemberborncommented, Jun 28, 2017

#1341 has landed. A new release will be out soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'split' of undefined while testing getting ...
vuejs2 - Cannot read property 'split' of undefined while testing getting this error - Stack Overflow. Stack Overflow for Teams – Start ...
Read more >
typeerror: cannot read property 'useeffect' of null - You.com | The ...
Firebase ReactJS useEffect TypeError: Cannot read property 'uid' of null ... made in a hook and that hook was used in the component...
Read more >
Npm start doesn't work - M220JS - MongoDB
after trying your commands, I'm getting Cannot read property 'split' of null error :cold_sweat: Fabii_08776 (Fabio Almeida Caetano) August ...
Read more >
TypeError: Cannot read property 'has' of undefined - Help
In your case, jsonData doesn't have the data property, so trying to access data's own username property will cause an error, not simply...
Read more >
Jest unit test fails with Error: Uncaught [TypeError: Cannot ...
Forum Thread - Jest unit test fails with Error: Uncaught [TypeError: Cannot read property 'id' of undefined] - React - EJ 2.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found