Commit 89c247f2 authored by Mark Florian's avatar Mark Florian Committed by Kushal Pandya

Don't override existing toHaveLength matcher

The `toHaveLength` matcher in `custom-jquery-matchers` doesn't work as
expected for generic Array-like objects with a `length` property,
whereas Jest's version does.

The reason is that the former wraps the value with jQuery, which only
correctly wraps _some_ Array-like objects, like true arrays, `jQuery
instances, `NodeList`s and `HTMLCollection`s.

As such, Jest's version is more widely useful, and is otherwise
equivalent, so it should be used instead.
parent 37f8a7f0
...@@ -113,10 +113,10 @@ describe('DependenciesApp component', () => { ...@@ -113,10 +113,10 @@ describe('DependenciesApp component', () => {
const expectNoHeader = () => expect(findHeader().exists()).toBe(false); const expectNoHeader = () => expect(findHeader().exists()).toBe(false);
const expectDependenciesTables = () => { const expectDependenciesTables = () => {
const { wrappers } = findDependenciesTables(); const tables = findDependenciesTables();
expect(wrappers).toHaveLength(2); expect(tables).toHaveLength(2);
expect(wrappers[0].props()).toEqual({ namespace: allNamespace }); expect(tables.at(0).props()).toEqual({ namespace: allNamespace });
expect(wrappers[1].props()).toEqual({ namespace: vulnerableNamespace }); expect(tables.at(1).props()).toEqual({ namespace: vulnerableNamespace });
}; };
const expectHeader = () => { const expectHeader = () => {
......
...@@ -42,10 +42,11 @@ describe('LogControlButtons', () => { ...@@ -42,10 +42,11 @@ describe('LogControlButtons', () => {
expect(findRefreshBtn().is(GlButton)).toBe(true); expect(findRefreshBtn().is(GlButton)).toBe(true);
}); });
it('emits a `refresh` event on click on `refersh` button', () => { it('emits a `refresh` event on click on `refresh` button', () => {
initWrapper(); initWrapper();
expect(wrapper.emitted('refresh')).toHaveLength(0); // An `undefined` value means no event was emitted
expect(wrapper.emitted('refresh')).toBe(undefined);
findRefreshBtn().vm.$emit('click'); findRefreshBtn().vm.$emit('click');
......
...@@ -57,6 +57,11 @@ Object.assign(global, { ...@@ -57,6 +57,11 @@ Object.assign(global, {
// custom-jquery-matchers was written for an old Jest version, we need to make it compatible // custom-jquery-matchers was written for an old Jest version, we need to make it compatible
Object.entries(jqueryMatchers).forEach(([matcherName, matcherFactory]) => { Object.entries(jqueryMatchers).forEach(([matcherName, matcherFactory]) => {
// Don't override existing Jest matcher
if (matcherName === 'toHaveLength') {
return;
}
expect.extend({ expect.extend({
[matcherName]: matcherFactory().compare, [matcherName]: matcherFactory().compare,
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment