Open
Description
Add a basic function, in src/services/FormatService.js
export default {
formatSize: function (s) {
console.log('String has endsWith: ' + (String.prototype.endsWith !== undefined))
return s.endsWith('_size')
}
}
Then the associated test:
import formatService from '@/services/FormatService'
describe('FormatService', () => {
it('should format size', () => {
expect(formatService.formatSize('test')).to.equal(false)
expect(formatService.formatSize('test_size')).to.equal(true)
})
})
The FormatService works perfectly in the browser (npm run dev), but it fails in the tests (npm run test) because the endsWith method is undefined on the String class:
LOG LOG: 'String has endsWith: false'
FormatService
✗ should format size
undefined is not a function (evaluating 's.endsWith('_size')')
formatSize@webpack:///src/services/FormatService.js:4:22 <- index.js:217:22
webpack:///test/unit/specs/FormatService.spec.js:5:32 <- index.js:12228:42
node 6.11.5
npm 3.10.10
vue-cli 2.9.1