dimanche 3 mars 2019

Testing using chai

I have this class and I want to test the methods in it using chai

    class BooksRepo {
        constructor() {
            this.fse = require('fs-extra');
            this.catalogFilePath = '../data/catalog.books.json';
        }


        async readFileAsync(filePath) {
            let data = await this.fse.readFile(filePath);
            let parsedData = await JSON.parse(data);
            return parsedData;
        }



        async getBook(bookName) {
            let books = await this.readFileAsync(this.catalogFilePath);
            let book = books.find(b => b.title == bookName);
            return book;
        }



module.exports = BooksRepo ;

This is how I am tying to do it

let expect = require('chai').expect
let BooksRepo = require('./BooksRepo');

    describe("BooksRepo class test case" , ()=>{
     it('search for book ', () => {
            expect(BooksRepo.getBook('Code Generation in Action')).to.equal('Code Generation in Action')

        });
    });

it gives me this error TypeError: BooksRepo.getBook is not a function

Aucun commentaire:

Enregistrer un commentaire