In Jasmine, array.includes does not work (should be replaced by other functions). What for?

My problem seems very strange. I have a constructor with a new, very simple function that should check if a variable is contained in an array. It works fine (I use this function on the form).

But ... I can not write Unit Test for this function, since Karma / Jasmine cannot see that the function "includes" from the array.

Can someone suggest me what to do? Here the situation is slightly simplified:

// Test constructor

vm.isNameAlreadyUsed = function () { //debut logging: console.log ("vm.allNames ",vm.allNames); // output: vm.allNames ['A', 'B', 'C'] console.log ("and vm.nameToBeChecked is ",vm.nameToBeChecked); //output: and vm.nameToBeChecked is 'A' return vm.allNames.includes(vm.nameToBeChecked); // The previous works as expected at runtime, but it causes the following exception in karma/jasmine: // TypeError: undefined is not a constructor (evaluating 'vm.allNames.includes(vm.nameToBeChecked) }; 

// Test (karma / jasmine)

  theConstructor.allNames = ["A", "B", "C"]; theConstructor.nameToBeChecked = "A"; var result theConstructor.isNameAlreadyUsed(); //error! expect(result).toBeTruthy(); 

Is it possible that jasmine cannot see the โ€œturn onโ€? the array is full, the variable is also ... and why should there be any constructor?

 TypeError: undefined is not a constructor (evaluating 'vm.allNames.includes(vm.nameToBeChecked) 

thanks


UPDATE

I noticed that in jasmine, any call "includes" causes an error. It doesnโ€™t depend on where. For example, just write the following code in a jasmine file to get an error message ... constructor (?!?):

 [1, 2, 3].includes(2); // TypeError: undefined is not a constructor (evaluating '[1, 2, 3].includes(2)') in ... 
+6
source share
1 answer

I would suggest that this is most likely due to one of two things:

0
source

Source: https://habr.com/ru/post/1011718/


All Articles