How to use expect - 10 common examples

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 swagger-api / swagger-ui / test / mocha / core / plugins / spec / actions.js View on Github external
it("should pass requestInterceptor/responseInterceptor to fn.execute", function(){
      // Given
      let configs = {
        requestInterceptor: createSpy(),
        responseInterceptor: createSpy()
      }
      const system = {
        fn: {
          buildRequest: createSpy(),
          execute: createSpy().andReturn(Promise.resolve())
        },
        specActions: {
          executeRequest: createSpy(),
          setMutatedRequest: createSpy(),
          setRequest: createSpy()
        },
        specSelectors: {
          spec: () => fromJS({}),
          parameterValues: () => fromJS({}),
          contentTypeValues: () => fromJS({}),
          url: () => fromJS({}),
          isOAS3: () => false
        },
        getConfigs: () => configs
      }
      // When
github redux-form / redux-form / src / __tests__ / reduxForm.spec.js View on Github external
it('should no resubmit if async submit is in progress', () => {
      const store = makeStore({
        testForm: {}
      })

      const Form = () => (
        <form>
          
          
        
      )

      const submitSpy = createSpy().andCall(() =&gt; new Promise(() =&gt; { /* Promise will never resolve */
      }))

      const Decorated = reduxForm({
        form: 'testForm',
        onSubmit: submitSpy
      })(Form)

      const dom = TestUtils.renderIntoDocument(
        
          
        
      )

      const stub = TestUtils.findRenderedComponentWithType(dom, Decorated)

      stub.submit()</form>
github swagger-api / swagger-editor / test / unit / plugins / editor / editor.js View on Github external
it("should be an event emitter", () => {
      // Given
      const fakeAce = new FakeAce()
      const spy = createSpy()
      fakeAce.on("foo", spy)

      // When
      fakeAce.emit("foo", "bar")

      // Then
      expect(spy.calls.length).toEqual(1)
      expect(spy.calls[0].arguments[0]).toEqual("bar")
    })
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 luckymarmot / API-Flow / src / models / __tests__ / Parameter.spec.js View on Github external
spyOn(__internals__, 'isReferenceParameter').andCall(({ reference }) => !!reference)
      spyOn(__internals__, 'getJSONSchemaFromReferenceParameter')
        .andCall(({ reference }) => reference)

      const inputs = [
        [ { simple: 123 }, false ],
        [ { sequence: 234 }, false ],
        [ { array: 345 }, false ],
        [ { reference: 456 }, false ],
        [ { other: 567 }, false ]
      ]
      const expected = [
        123, 234, 345, 456, {}
      ]
      const actual = inputs.map(input => __internals__.getRawJSONSchema(...input))
      expect(actual).toEqual(expected)
    })
    /* eslint-enable max-statements */
github goblindegook / dictionary-react-redux-typescript / test / typings / expect.spec.ts View on Github external
function test_spies() {
  // Spy
  const spy = expect.createSpy&lt;(a: number) =&gt; number&gt;()
  expect.isSpy(spy);
  const otherSpy = expect.spyOn({}, "test");
  expect.restoreSpies();

  spy.andCall(() =&gt; {});
  spy.andCallThrough();
  spy.andReturn(1);
  spy.andThrow(new Error("test"));
  spy.restore();

  spy(1);
  spy.calls[0].arguments;
  spy.calls[0].context;

  expect(spy).toBe(spy);
  expect(spy).toEqual(spy);
  expect(spy).toExist();
  expect(spy).toHaveBeenCalled();
  expect(spy).toHaveBeenCalledWith();
github peerigon / alamid / test / testHelpers / expect.jquery.js View on Github external
"use strict"; // run code in ES5 strict mode

var expect = require("expect.js"),
    $ = require("../testHelpers/jquery.js");

var proto = expect.Assertion.prototype,
    be = proto.be,
    eql = proto.eql,
    a = proto.a,
    contain = proto.contain,
    empty = proto.empty;

// don't extend it when it's already extended
if (!expect.jQuery) {
    expect.jQuery = true;

    proto.be =
    proto.equal = function (obj) {
        this.obj = unwrap(this.obj);
        obj = unwrap(obj);
        be.call(this, obj);
    };
github tomchentw-deprecated / redux-component / src / components / __tests__ / Componentize.spec.js View on Github external
const spies = Object.keys(lifecycleCallbacks).reduce((acc, key) => {
          /* eslint-disable no-param-reassign */
          acc[key] = expect.spyOn(lifecycleCallbacks, key);
          /* eslint-enable no-param-reassign */
          return acc;
        }, {});
github WorldBrain / Memex / src / custom-lists / background / index.tests.ts View on Github external
pages: ['http://www.bla.com/'],
                                    active: true,
                                })

                                expect(
                                    await customLists(setup).fetchListPagesById(
                                        {
                                            id: listId,
                                        },
                                    ),
                                ).toEqual([
                                    {
                                        listId,
                                        pageUrl: 'bla.com',
                                        fullUrl: 'http://www.bla.com/',
                                        createdAt: expect.any(Date),
                                    },
                                ])

                                // expect(await setup.backgroundModules.search.remoteFunctions.search.searchPages({
                                //     contentTypes: { pages: true, notes: false, highlights: false },
                                //     collections: [listId]
                                // })).toEqual([])
                            },
                        },

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