Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

unit testing for react

The testing ecosystem are Jest and Testing Library but mocha works.
Comment

how to write unit test cases in react js

# Given a component
import React from 'react';
const Hi = ({ userName }) => (
  <div className="sayhello">Howdy, {userName}!</div>
);
export default Hi;

# Install required deps
npm install --save-dev riteway

# Unit test
import React from 'react';
import { describe } from 'riteway';
import render from 'riteway/render-component';
import match from 'riteway/match';
import Hi from '../hi';
describe('Hi component', async assert => {
  const userName = 'MeMyself';
  const $ = render(<Hello userName={userName} />);
  const contains = match($('.sayhello').html());
  assert({
    given: 'A user',
    should: 'It should render a correct username.',
    actual: contains(userName),
    expected: `Hi, ${userName}!`
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add alert on javascript 
Javascript :: javascript for validation 
Javascript :: Angular 4 "Property does not exist on type component" 
Javascript :: function statement js 
Javascript :: how to sort an array 
Javascript :: JavaScript Debug usage Example 
Javascript :: js int 
Javascript :: random string javascript 
Javascript :: what is palindrome 
Javascript :: !! javascript 
Javascript :: discord.js reply to message author 
Javascript :: pretty print javascript 
Javascript :: google app script 
Javascript :: react class names 
Javascript :: js timer 
Javascript :: some js 
Javascript :: jquery check if click to this self not this child 
Javascript :: js.l1 
Javascript :: javascript sort strings alphabetically 
Javascript :: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms 
Javascript :: js array to scsv 
Javascript :: bootstrap 4 without javascript 
Javascript :: Pure JavaScript Send POST NO JQUERY 
Javascript :: generators javascript in class 
Javascript :: attach a generated pdf to a smtpjs mail in js 
Javascript :: sum of array odd number javascript 
Javascript :: string and charater alphabet order 
Javascript :: external javascript files can be cached 
Javascript :: 300000/12 
Javascript :: can I pass function as prop on route change 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =