android-logo

Jest API Testing


Here we will see how to test API using Jest.


Movies.js


class Movies{

    api(){
        return fetch("https://reactnative.dev/movies.json") 
        .then((response) =>{
            return response.json();
        })
     }
    }
    
export default Movies;

App.test.js


import Movies from './Movies';


it("API test", async function(){

    const response = new Movies();
    var data = await response.api();

    expect(data.movies[1].releaseYear).toBe("1985");
})

To Run test we use below command


npm test

jest-test

previous-button

facebook-logo
twitter-logo
instagram-logo

2020 © All rights reserved.