0

My site is using react and node . For that I created the test case using enzyme at react side and from server site I am using Mocha. Both are working correctly when I am using terminal command (npm test) its showing fail ans success result. But I want to do test case from ui interface .

Basically i want to backed (nodejs) function fronted with one command, Now my test case working on different terminal For example for react I am opened in one terminal and for node side test case I oped another terminal.

this is my node side code :-

const request = require('supertest');
const expect = require('chai').expect;
const req = 'http://localhost:3000';
 this.user_id = '';

describe('Register form', function() {
    it('User saved successfully in database', function(done) {
        request(req)
           .post('/users/register')
           .set('Accept', 'application/json')
           .set('Content-Type', 'application/json')
           .send({user:{disabled: false,
                    email: "[email protected]",
                    firstName: "test",
                    lastName: "test",
                    password: "24234234ds",
                    roles: "hr",
                    status: "verified"}})
           .expect(200)
           .expect('Content-Type', /json/)
           .expect(function(response) {
           })
           .end(done);
    }); 
});

and this is react side code:-

import React from 'react';
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';
import Select from 'react-select'
import config from 'config';
import { Alert } from 'reactstrap';
import { userActions } from '../../../src/actions';

import Enzyme, {shallow,mount,render,unmount} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import RegisterPage from '../../../src/features/RegisterPage/RegisterPage';
import { MemoryRouter } from 'react-router-dom';

Enzyme.configure({adapter: new Adapter()});

describe('In register page check react syntex', () => {
  it('Should RegisterPage shallow correctly in "debug" mode', () => {
    const component = (<RegisterPage debug />);
    expect(component).toMatchSnapshot();
  });
}); 

describe('On register page count input filed', () => {
     it('Total text filed', () => {
      expect(shallow(<RegisterPage />).find('input[type="text"]').length).toEqual(2)
     })
    it('Total email filed', () => {
      expect(shallow(<RegisterPage />).find('input[type="email"]').length).toEqual(1)
     })
    it('Total checkbox filed', () => {
      expect(shallow(<RegisterPage />).find('input[type="checkbox"]').length).toEqual(1)
     })
    it('Total radio filed', () => {
      expect(shallow(<RegisterPage />).find('input[type="radio"]').length).toEqual(2)
     })
}); 


describe('On Register page check firstname , lastname or email address vaildation', () => {  
  it('Check first name in registerpage ', () => {
   const wrapper = mount(<RegisterPage />);
   wrapper.find('input[name="firstName"]').simulate('change', {target: {name: 'firstName', value: 'dinesh'}}); 
   expect(wrapper.state().user.firstName).toEqual('dinesh');    
  })

  it('Check lastname in register page ', () => {
   const wrapper = mount(<RegisterPage />);
   wrapper.find('input[name="lastName"]').simulate('change', {target: {name: 'lastName', value: 'Sharma'}});
   expect(wrapper.state().user.lastName).toEqual('Sharma');   
  })

  it('Check email address in register page', () => {
  const wrapper = mount(<RegisterPage />);
  wrapper.find('input[name="email"]').simulate('change', {target: {name: 'email', value: '[email protected]'}});
  expect(wrapper.state().user.email).toEqual('[email protected]');   
  })

})
2
  • So your question is a little unclear. Do you want to run both the front and backend tests together with one command in one terminal? Commented Sep 20, 2019 at 11:36
  • Yes right understanding Commented Sep 20, 2019 at 12:02

1 Answer 1

1

If you want to run front end and back end test together in one terminal you can modify your package.json scripts section to look something like this.

{
    "scripts": {
        "test": "mocha <path to node test files> && jest <path to react test files>"
    }
}

Every time you run npm test both sets of tests will run.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.