Giter Site home page Giter Site logo

jasmine-expect-jsx's Introduction

jasmine-expect-jsx npm Build Status

Greenkeeper badge

Adds toEqualJSX and toIncludeJSX methods to jasmine assertions. Uses Algolia's react-element-to-jsx-string under the hood.

Installation

npm install -D jasmine-expect-jsx

Setup

Browser

<script src="/path/to/jasmine-expect-jsx.js"></script>

Karma

Integration is easy with the karma-jasmine-expect-jsx plugin and it provides colored output.

Also you can just add 'node_modules/jasmine-expect-jsx/dist/jasmine-expect-jsx.js' to files section of your config.

Node.js

require('jasmine-expect-jsx');

Jest

  1. Add setupTestFrameworkScriptFile in package.json
{
    ...
    "jest": {
        "setupTestFrameworkScriptFile": "<rootDir>/jestSetup.js"
    }
    ...
}
  1. Import jasmine-expect-jsx in setupTestFrameworkScriptFile file
// jestSetup.js
require('jasmine-expect-jsx');

Usage

The following tests are all passing:

Expect

class TestComponent extends React.Component {}

// equalJSX
expect(<div />).toEqualJSX(<div />);
expect(<TestComponent />).toEqualJSX(<TestComponent />);

expect(<div />).not.toEqualJSX(<span />);
expect(<TestComponent />).not.toEqualJSX(<span />);

// includeJSX
expect(<div><span>Hello World!</span></div>).toIncludeJSX(<span>Hello World!</span>);
expect(<TestComponent />).toIncludeJSX(<SomeSubComponent />); // assuming <SomeSubComponent /> is rendered by TestComponent's render

expect(<div><span>Hello World!</span></div>).not.toIncludeJSX(<span>Hello World!</span>);
expect(<TestComponent />).not.toIncludeJSX(<SomeSubComponent />); // assuming <SomeSubComponent /> is not rendered by TestComponent's render

jasmine-expect-jsx's People

Contributors

ahuth avatar greenkeeper[bot] avatar hieuhlc avatar smacker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jasmine-expect-jsx's Issues

new feature of react-element-to-jsx-string not being pulled in

react-element-to-jsx-string recently added fragment support.

I tried to use it with jasmine-expect-jsx but it seems to not be used. I noticed that the generated bundle contains react-element-to-jsx-string's code rather than importing it.

In the short term, would it be possible to upgrade dependencies and do a new release?

In the long term, I think switching to a rollup bundle that imported react-element-to-jsx-string would make it unnecessary to do a release every time they released. That could make it harder to make a bundle that runs in the browser though, so as an alternative there could be a post-install step that builds the bundle from whatever versions are currently in node modules.

An in-range update of react-element-to-jsx-string is breaking the build 🚨

The dependency react-element-to-jsx-string was updated from 14.0.2 to 14.0.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

react-element-to-jsx-string is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 163 commits.

  • e658098 14.0.3
  • 5fe7604 feat(sortObject): Add a test for issue 344 (#357)
  • 8c6d6af test(travis): add node 12 (#381)
  • e923b03 chore(deps): update dependency flow-copy-source to v2.0.7
  • 1295b9d chore(deps): update dependency eslint-plugin-jest to v22.7.2
  • abe13f9 chore(deps): update dependency eslint-config-algolia to v13.4.0
  • 8dc4e11 chore(deps): update dependency husky to v2.7.0
  • c131d91 chore(deps): update dependency flow-bin to v0.102.0
  • 710a17c chore(deps): update dependency eslint-plugin-react to v7.14.2
  • 8ac7e48 chore(deps): update dependency eslint-plugin-import to v2.18.0
  • d5982a1 chore(deps): update dependency eslint-plugin-jest to v22.7.1
  • 9291715 chore(deps): update dependency flow-bin to v0.101.1
  • 8752ad1 chore(deps): update dependency eslint-plugin-jest to v22.7.0
  • ff589c2 chore(deps): update dependency babel-eslint to v10.0.2
  • cb87f27 chore(deps): update dependency lint-staged to v8.2.1

There are 163 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of browserify is breaking the build 🚨

The devDependency browserify was updated from 16.3.0 to 16.4.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

browserify is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 5 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Usage with Jest

Hello,
I am trying to use jasmine-expect-jsx with jest and the example shown below but I am still getting the following error:
TypeError: expect(...).toEqualJSX is not a function

jest.dontMock('../Main.jsx');

let React = require('react');
require('jasmine-expect-jsx');

describe('Main Component', () => {
  it('renders the Main component', () => {
    expect( < div / > ).toEqualJSX( < div / > );
  });

});

What is the recommended way to use this package with jest?

An in-range update of react is breaking the build 🚨

There have been updates to the react monorepo:

    • The devDependency react was updated from 16.6.1 to 16.6.2.
  • The devDependency react-dom was updated from 16.6.1 to 16.6.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the react group definition.

react is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of react is breaking the build 🚨

Version 16.4.2 of the react packages was just published.

Branch Build failing 🚨
Monorepo release group react
Current Version 16.4.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the react group definition.

react is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes v16.4.2

16.4.2 (August 1, 2018)

React DOM Server

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of eslint-plugin-react is breaking the build 🚨

The devDependency eslint-plugin-react was updated from 7.14.0 to 7.14.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-react is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v7.14.1

Fixed

  • Fix prop-types crash on multiple destructuring (#2319 @golopot)
Commits

The new version differs by 3 commits.

  • 62255af Update CHANGELOG and bump version
  • 655eb01 Merge pull request #2320 from golopot/issue-2319
  • 9639d82 [Fix] prop-types: fix crash on multiple destructuring

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

.not.toEqualJSX() not working with jest

I managed to get jasmine-expect-jsx working, however I can see some strange behavior.

We have LoginPage component which renders simple div

<div className="LoginPage"></div>

I would like to check if that is what realy gets rendered.

renderer = createRenderer();
renderer.render(<LoginPage/>);
component = renderer.getRenderOutput();

const expected = <div className="LoginPage"></div>;
expect(component).toEqualJSX(expected);

And it is working fine. If i change the expected div class to something else

const expected = <div className="wrongClassName"></div>;

It's still working fine, i get nice output where i can see what is wrong.

And now, when i try to do the same, but with negation using the .not.

const expected = <div className="LoginPage"></div>;
expect(component).not.toEqualJSX(expected);

I would expect it should fail, but the test still pases which is very weird. When i then change the classname for anything else i.e.

const expected = <div className="wrongClass"></div>;
expect(component).not.toEqualJSX(expected);

I got "No message was specified fo this matcher".

I am using Jest 19.0.2.
I've also tried enzyme shallow.debug() to get the output instead createRenderer() with the same result.

bug: es6 contained in es5 output

i'm getting unexpected token > all over the place when including the newest jasmine-expect-jsx because the dist output seems to have fat arrows.

for example, line 2418:

module.exports = object => {

it looks like it happened with the recent pr to update react-element-to-jsx-string but their output doesn't seem to contain any fat arrows.

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 5.15.3 to 5.16.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v5.16.0
  • dfef227 Build: gensite passes rulesMeta to formatter rendering (#11567) (Kevin Partington)
  • c06d38c Fix: Allow HTML formatter to handle no meta data (#11566) (Ilya Volodin)
  • 87a5c03 Docs: func-style: clarify when allowArrowFunctions is used (#11548) (Oliver Joseph Ash)
  • bc3e427 Update: pass rule meta to formatters RFC 10 (#11551) (Chris Meyer)
  • b452f27 Chore: Update README to pull in reviewer data (#11506) (Nicholas C. Zakas)
  • afe3d25 Upgrade: Bump js-yaml dependency to fix Denial of Service vulnerability (#11550) (Vernon de Goede)
  • 4fe7eb7 Chore: use nyc instead of istanbul (#11532) (Toru Nagashima)
  • f16af43 Chore: fix formatters/table test (#11534) (Toru Nagashima)
  • 78358a8 Docs: fix duplicate punctuation in CLI docs (#11528) (Teddy Katz)
Commits

The new version differs by 11 commits.

  • ded2f94 5.16.0
  • ea36e13 Build: changelog update for 5.16.0
  • dfef227 Build: gensite passes rulesMeta to formatter rendering (#11567)
  • c06d38c Fix: Allow HTML formatter to handle no meta data (#11566)
  • 87a5c03 Docs: func-style: clarify when allowArrowFunctions is used (#11548)
  • bc3e427 Update: pass rule meta to formatters RFC 10 (#11551)
  • b452f27 Chore: Update README to pull in reviewer data (#11506)
  • afe3d25 Upgrade: Bump js-yaml dependency to fix Denial of Service vulnerability (#11550)
  • 4fe7eb7 Chore: use nyc instead of istanbul (#11532)
  • f16af43 Chore: fix formatters/table test (#11534)
  • 78358a8 Docs: fix duplicate punctuation in CLI docs (#11528)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Update dependencies

Hi,
I noticed that there is a dependency on react even though it's not used directly. I believe it could be removed (react-element-to-jsx-string) already has a peer dependency.

Also, react-element-to-jsx-string is on version 13 now. Is it possible to upgrade to use the latest version?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.