I am a JavaScript Freelancer - React.js, Vue.js, Node.js
meuschke / relay-testing-utils Goto Github PK
View Code? Open in Web Editor NEWEasy to use relay mock and unit testing tool (works with Jest & Enzyme)
License: MIT License
Easy to use relay mock and unit testing tool (works with Jest & Enzyme)
License: MIT License
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)
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");
});
});
Find a way to create random fixture data based on the GraphQL schema.
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 });
Create a way to insert a spy to test relay mutations properly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.