Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

This test checks whether the Model we are describing exists or not. Let's run the test using


the following command:


$ mocha test/unit/specs/models/Movie.spec.js

The test should pass with the following output:


Let's move on to add a test when we send the release_year attribute of the Movie a


string. Since we have a validation for the release_year attribute, sending a string value to


it should throw an error.


Replace the contents in Movie.spec.js with the following code:


var Movie = require("./../../../../models/Movie.js");
let chai = require('chai');
var expect = chai.expect;
var should = chai.should();

describe('models.Movie', function(){
it('exists', function(){
expect(Movie).to.exist
})

describe('Movie', function() {
it('should be invalid if release_year is not an integer',
function(done){
var movie = new Movie({
name: 'test',
description: 'test',
release_year: 'test',
genre: 'test'
});

movie.validate(function(err){
Free download pdf