Using Chai in Vue.js - for some reason my test looked like this .
it('Home page message', function(done) {
request('http://localhost:8080' , function(error, response, body) {
expect(body.$('div.app').text().to.have.string('Cornwall'));
done();
});
});
This was returning the error
Uncaught TypeError: body.$ is not a function
To fix this wanted to see 'body' was, so added the code
console.log(body)
The 'console.log' prints out in your terminal. The print out looks like a string , and this can be confirmed with.
console.log(typeof body)
From here on I can use 'search' on the string for the text I'm looking for .
var expect = require('chai').expect;
var request = require('request');
it('Home page message', function(done) {
request('http://localhost:8080' , function(error, response, body) {
expect(body.search('Cornwall'));
done();
});
});
Additionally if you want to turn the 'body' into DOM objects then we can use 'jsdom'
I'll have a code example for this soon.
No comments:
Post a Comment