Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit d79af08

Browse files
authored
fix(top-app-bar): Fix testdouble warning about using both stub & verify. (#2793)
Moved number of calls check to when() on stub using `times`.
1 parent 5d0f614 commit d79af08

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

test/unit/mdc-top-app-bar/mdc-top-app-bar.test.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import MDCTopAppBarFoundation from '../../../packages/mdc-top-app-bar/foundation
2626
import MDCFixedTopAppBarFoundation from '../../../packages/mdc-top-app-bar/fixed/foundation';
2727
import MDCShortTopAppBarFoundation from '../../../packages/mdc-top-app-bar/short/foundation';
2828

29+
const MENU_ICONS_COUNT = 3;
30+
2931
function getFixture(removeIcon) {
3032
const html = bel`
3133
<div>
@@ -66,11 +68,6 @@ function getFixture(removeIcon) {
6668
return html;
6769
}
6870

69-
function getIconsCount(root) {
70-
const selector = strings.ACTION_ITEM_SELECTOR + ',' + strings.NAVIGATION_ICON_SELECTOR;
71-
return root.querySelectorAll(selector).length;
72-
}
73-
7471
class FakeRipple {
7572
constructor(root) {
7673
this.root = root;
@@ -96,20 +93,19 @@ test('attachTo initializes and returns an MDCTopAppBar instance', () => {
9693

9794
test('constructor instantiates icon ripples for all icons', () => {
9895
const rippleFactory = td.function();
99-
td.when(rippleFactory(td.matchers.anything())).thenReturn((el) => new FakeRipple(el));
100-
const {root} = setupTest(/** removeIcon */ false, rippleFactory);
96+
// Including navigation icon.
97+
const totalIcons = MENU_ICONS_COUNT + 1;
10198

102-
const totalIcons = getIconsCount(root);
103-
td.verify(rippleFactory(td.matchers.anything()), {times: totalIcons});
99+
td.when(rippleFactory(td.matchers.anything()), {times: totalIcons}).thenReturn((el) => new FakeRipple(el));
100+
setupTest(/** removeIcon */ false, rippleFactory);
104101
});
105102

106103
test('constructor does not instantiate ripple for nav icon when not present', () => {
107104
const rippleFactory = td.function();
108-
td.when(rippleFactory(td.matchers.anything())).thenReturn((el) => new FakeRipple(el));
109-
const {root} = setupTest(/** removeIcon */ true, rippleFactory);
105+
const totalIcons = MENU_ICONS_COUNT;
110106

111-
const totalIcons = getIconsCount(root);
112-
td.verify(rippleFactory(td.matchers.anything()), {times: totalIcons});
107+
td.when(rippleFactory(td.matchers.anything()), {times: totalIcons}).thenReturn((el) => new FakeRipple(el));
108+
setupTest(/** removeIcon */ true, rippleFactory);
113109
});
114110

115111
test('destroy destroys icon ripples', () => {

0 commit comments

Comments
 (0)