TypeError: array.every is not a function
See original GitHub issueWhen running npm t i get the “TypeError: array.every is not a function” error. My code is very similar to yours.
var expect = require('chai').expect;
var dogBreedNames = require('./index');
describe('Dog breeds?', function () {
describe('all', function () {
it('should be a array of strings', function () {
expect(dogBreedNames.all).to.satisfy(isArrayOfStrings);
function isArrayOfStrings(array) {
return array.every(function(item){
return typeof item === 'string'
});
}
});
});
});
and the index.js is the following:
var uniqueRandomArray = require('unique-random-array');
var dogBreedNames = require('./dogs.json');
var getRandomItem = uniqueRandomArray(dogBreedNames);
module.exports = {
all: dogBreedNames,
random: uniqueRandomArray(dogBreedNames)
};
function random(number) {
if (number === undefined) {
return getRandomItem();
} else {
var randomItems = [];
for (var i = 0; i < number; i++) {
randomItems.push(getRandomItem());
}
return randomItems;
}
}
Thanks, -Sohail
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:11 (3 by maintainers)
Top Results From Across the Web
How to solve every is not a function in JavaScript
The “every is not a function” error occurs, when we call a every() method on a value which is not array. To fix...
Read more >Why is .every() not a function?
No, it's just jQuery object. jQuery objects are very array-like, but they aren't arrays. Worse, they have some array-like methods (such as ...
Read more >Solve - every is not a function in JavaScript
The “every is not a function” error occurs, when we call a every() method on a value which is not array. To fix...
Read more >Array.prototype.every() - JavaScript - MDN Web Docs
The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value....
Read more >TypeError: some is not a function in JavaScript [Solved]
The "TypeError: some is not a function" error occurs when the some() method is called on a value that is not an array....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Solved it, there was the white space in travis.yml file for the script code, and I also needed to change the script attribute from -npm run test:single to
Thanks, I have been looking at that code 😃