Giter VIP home page Giter VIP logo

relay-testing-utils's Introduction

Hi there, my name is Toni ๐Ÿ‘‹

I am a JavaScript Freelancer - React.js, Vue.js, Node.js

๐Ÿ‘จโ€๐Ÿ’ป Technical Skills

JavaScript NodeJS Vue React HTML5 Postgres

๐Ÿค Get in touch

React

relay-testing-utils's People

Contributors

meuschke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

relay-testing-utils's Issues

TypeError: Class extends value undefined is not a function or null

I get the following error when trying to use this module in my tests:

TypeError: Class extends value undefined is not a function or null
  
  at Object.relayMock (node_modules/relay-testing-utils/build/relay-mock.js:9:31)
  at Object.<anonymous> (src/components/__mocks__/react-relay.js:6:49)
  at Object.<anonymous> (src/components/filter.tsx:10:2)
  at Object.<anonymous> (src/components/__tests__/filter.test.tsx:2:1)

TypeError: Class constructor Mutation cannot be invoked without 'new'

Hi, I'm having a little trouble testing a mutation:

I'm getting

TypeError: Class constructor Mutation cannot be invoked without 'new'

      1 | import Relay from "react-relay/classic";
      2 |
    > 3 | export default class UpdateBidMutation extends Relay.Mutation {
      4 |   getMutation() {
      5 |     return Relay.QL`mutation{updateBid}`;
      6 |   }

When testing the following code - could this be a problem with how the testing utils are mocking out Relay? The code works perfectly in production, it just blows up on this test

// test/__mocks__/react-relay.js:

import relayTestingUtils from 'relay-testing-utils'
const relay = jest.genMockFromModule('react-relay/classic');
export default relayTestingUtils.relayMock(relay)
// component.js:

import React from "react";
import Relay from "react-relay/classic";
import UpdateBidMutation from "../../mutations/update-bid";
//...
class UndoButton extends React.Component {

  undo() {
    const newState = { // ... irrelevant stuff here};

    let mutation = new UpdateBidMutation({
      bid: {
        id: this.props.bid.id,
        ...newState
      }
    });
  //...
  }
}

export default Relay.createContainer(UndoButton, {
  fragments: {
    bid: () => Relay.QL`
      fragment on Bid {
        id
        state
      }  
    `
  }
});
// mutations/update-bid.js:

import Relay from "react-relay/classic";

export default class UpdateBidMutation extends Relay.Mutation {
  getMutation() {
    return Relay.QL`mutation{updateBid}`;
  }
//.. etc etc
// undo-button.spec.js:

import React from "react";
import Relay from "react-relay/classic";
import {mount} from "enzyme";
import relayTestingUtils from "relay-testing-utils";
import UndoButton from "./undo-button";
//...
  describe("Undo mutation", () => {
    let spy;
    let wrapper;

    beforeEach(() => {
      spy = jest.fn();
      Relay.Store.mockCommitUpdate(spy);
      wrapper = mount(relayTestingUtils.relayWrap(<UndoButton {...fixture} {...props}/>));
    });

    it("fires an UpdateBidMutation", () => {
      wrapper.find("a").simulate("click");
      expect(spy.mock.calls[0][0].getVariables().text).toBe("something");
    });
  });

Relay Modern TypeError: Class extends value undefined is not a function or null

just to make sure does this work with Relay Modern?

getting the error:

TypeError: Class extends value undefined is not a function or null
1 import relayTestingUtils from 'relay-testing-utils';
2 import { mount } from 'enzyme';
3 import City from './index';
4
5 const City_item = {
6 _id: 1
7 }
8
9 describe('map should', () => {
10 const elJson = mount(
11 relayTestingUtils.wrapRelay(<City {...City_item} />)
12 );
13 it('match a snapshot', () => {
14 //expect(elJson).toMatchSnapshot();
15 });
16 });

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.