How to use the expect.extend function in expect

To help you get started, we’ve selected a few expect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github threepointone / routah / tests / index.js View on Github external
/* global describe, it, beforeEach, afterEach */

import React, { Component, PropTypes } from 'react'
import { render, unmountComponentAtNode } from 'react-dom'
import { findRenderedDOMComponentWithTag, Simulate } from 'react-addons-test-utils'
import { Route, Router, Link, Redirect, RouteStack, connectHistory } from '../src'
import { createMemoryHistory } from 'history'

import expect from 'expect'
import expectJSX from 'expect-jsx'
expect.extend(expectJSX)


describe('Router', () => {
  let node
  beforeEach(() => node = document.createElement('div'))
  afterEach(() => unmountComponentAtNode(node))

  it('will introduce a `history` context', done => {
    class App extends Component {
      static contextTypes = {
        history: PropTypes.object
      }
      componentDidMount() {
        expect(this.context.history).toExist()
        done()
      }
github threepointone / routah / tests / server.js View on Github external
/* global describe, it */
import React, {Component, PropTypes} from 'react';
import {Router, Route} from '../src';
import {renderToString, renderToStaticMarkup} from 'react-dom/server';
import {createMemoryHistory} from 'history';

import expect from 'expect';
import expectJSX from 'expect-jsx';
expect.extend(expectJSX);

describe('server side routah', () => {
  it('prop: history', done => {
    class App extends Component{
      static contextTypes = {
        history: PropTypes.object
      };
      componentWillMount(){
        this.context.history.listen(l => expect(l.pathname).toEqual('/xyz'))();
        done();
      }
      render(){
        return null;
      }
    }
github artsy / emission / src / setupJest.ts View on Github external
// declare var babelHelpers: any
// Object.assign(babelHelpers, { applyDecoratedDescriptor, initializerDefineProperty })
// import "@babel/runtime"

import chalk from "chalk"
import Enzyme from "enzyme"
import Adapter from "enzyme-adapter-react-16"
import expect from "expect"
import { format } from "util"

import "lib/tests/renderUntil"
Enzyme.configure({ adapter: new Adapter() })

// Waiting on https://github.com/thymikee/snapshot-diff/pull/17
import diff from "snapshot-diff"
expect.extend({ toMatchDiffSnapshot: (diff as any).toMatchDiffSnapshot })

jest.mock("react-tracking")
import _track from "react-tracking"
const track = _track as jest.Mock
track.mockImplementation((_ => x => x) as any)

// Mock this separately so react-tracking can be unmocked in tests but not result in the `window` global being accessed.
jest.mock("react-tracking/build/dispatchTrackingEvent")

jest.mock("./lib/NativeModules/NotificationsManager.tsx", () => ({
  NotificationsManager: {
    addListener: jest.fn(),
  },
}))

jest.mock("@mapbox/react-native-mapbox-gl", () => ({
github LouisBarranqueiro / reapop / test / components / Notifications.js View on Github external
import React from 'react';
import expect from 'expect';
import expectJSX from 'expect-jsx';
import TransitionGroup from 'react/lib/ReactCSSTransitionGroup';
import {
  defaultValues,
  className,
  transition,
  Notifications
} from '../../src/components/Notifications/Notifications';
import {className as notificationClassName} from '../../src/components/Notification/Notification';
import STATUS from '../../src/constants';
import {shallowRender, render} from '../helpers';

expect.extend(expectJSX);

describe('Notifications', () => {
  it('should render component with correct JSX structure', () => {
    const component = shallowRender(Notifications);
    let expectedElement = (
      <div>
        
      </div>
    );
    expect(component).toEqualJSX(expectedElement);
  });
  
  it('should render component with its default props', () =&gt; {
github webkom / lego-webapp / testing / test-bundler.js View on Github external
import 'babel-polyfill';

import moment from 'moment';
import expect from 'expect';
import expectJSX from 'expect-jsx';
import sinon from 'sinon';
import chai from 'chai';
import chaiEnzyme from 'chai-enzyme';

chai.use(chaiEnzyme());

moment.locale('nb-NO');

expect.extend(expectJSX);

global.chai = chai;
global.sinon = sinon;
global.expect = chai.expect;
global.should = chai.should();
global.window = document.defaultView;
global.navigator = global.window.navigator;

const context = require.context('../app', true, /.spec\.js$/);
context.keys().forEach(context);
github phenomic / phenomic / src / components / BodyContainer / __tests__ / index.js View on Github external
import test from "jest-ava-api"
import React from "react"
import { createRenderer } from "react-addons-test-utils"
import expect from "expect"
import expectJSX from "expect-jsx"

import BodyContainer from "../index.js"

expect.extend(expectJSX)
const Noop = () =&gt; {}

test("should wrap html", () =&gt; {
  const html = "<a>test</a>"
  const renderer = createRenderer()
  renderer.render(
    { html }
  )
  expect(renderer.getRenderOutput()).toEqualJSX(
    <div>
  )
})
</div>
github souhe / reactScrollbar / test / scrollArea.spec.js View on Github external
import expect from 'expect';
import expectJSX from 'expect-jsx';
expect.extend(expectJSX);

import React, { Component } from 'react';
import {render} from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import ScrollArea from '../src/js/ScrollArea';
import Scrollbar from '../src/js/Scrollbar';

function setup(props, sizes){
    let renderer = TestUtils.createRenderer();
    renderer.render(<p>content</p>);
    let instance = getRendererComponentInstance(renderer);

    if(sizes){
        instance.computeSizes = () =&gt; sizes;
        instance.setSizesToState();
    }
github clintonhalpin / react-image-panel / test / Panel.spec.js View on Github external
import 'babel-polyfill';
import expect from 'expect';
import expectJSX from 'expect-jsx';
expect.extend(expectJSX);
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import { Panel } from './../src/';

function setup() {
  let renderer = TestUtils.createRenderer();
  renderer.render()
  let output = renderer.getRenderOutput();

  return {
    output,
    renderer
  }
}

describe('components', () =&gt; {
github thefrontside / effection.js / tests / typescript / matcher.js View on Github external
import expect from 'expect';
import path from 'path';

import { createProgram, getPreEmitDiagnostics } from 'typescript';

expect.extend({
  toCompile(received) {
    let diagnostics = compile(received);
    let pass = diagnostics.length == 0;
    if (pass) {
      return {
        pass,
        message: () =>
          `expected '${received}' to compile with errors, but it compiled cleanly`
      };
    } else {
      return {
        pass,
        message: () =>
          `expected '${received}' to compile without errors, but it failed:

${formatTypescriptDiagnostics(diagnostics)}`

expect

This package exports the `expect` function used in [Jest](https://jestjs.io/). You can find its documentation [on Jest's website](https://jestjs.io/docs/expect).

MIT
Latest version published 1 year ago

Package Health Score

88 / 100
Full package analysis