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

Commit

Permalink
refactor: Add declare to class fields in child class that overrides a…
Browse files Browse the repository at this point in the history
… base class field without explicitly reinitializing the field.

PiperOrigin-RevId: 679034213
  • Loading branch information
material-web-copybara authored and copybara-github committed Sep 26, 2024
1 parent 271ca16 commit 2123067
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions packages/mdc-switch/test/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
*/

import {createFixture, html} from '../../../testing/dom';
import {spyOnAllFunctions, spyOnAllPrototypeFunctions} from '../../../testing/helpers/jasmine';
import {
spyOnAllFunctions,
spyOnAllPrototypeFunctions,
} from '../../../testing/helpers/jasmine';
import {setUpMdcTestEnvironment} from '../../../testing/helpers/setup';
import {MDCSwitchRenderAdapter} from '../adapter';
import {MDCSwitch} from '../component';
Expand Down Expand Up @@ -61,11 +64,12 @@ class MockMDCSwitch extends MDCSwitch {
}

adapter!: jasmine.SpyObj<MDCSwitchRenderAdapter>;
override foundation!: jasmine.SpyObj<MDCSwitchRenderFoundation>;
declare foundation: jasmine.SpyObj<MDCSwitchRenderFoundation>;

override getDefaultFoundation() {
const foundation = spyOnAllPrototypeFunctions(super.getDefaultFoundation())
.and.callThrough();
const foundation = spyOnAllPrototypeFunctions(
super.getDefaultFoundation(),
).and.callThrough();
this.foundation = this.foundation || foundation;
return foundation;
}
Expand Down Expand Up @@ -101,12 +105,11 @@ describe('MDCSwitch', () => {
expect(foundation.initFromDOM).toHaveBeenCalledTimes(1);
});

it('#initialSyncWithDOM() adds foundation.handleClick listener to root',
() => {
const {root, foundation} = setupTest();
root.click();
expect(foundation.handleClick).toHaveBeenCalledTimes(1);
});
it('#initialSyncWithDOM() adds foundation.handleClick listener to root', () => {
const {root, foundation} = setupTest();
root.click();
expect(foundation.handleClick).toHaveBeenCalledTimes(1);
});

it('#destroy() removes foundation.handleClick listener from root', () => {
const {component, root, foundation} = setupTest();
Expand All @@ -124,11 +127,15 @@ describe('MDCSwitch', () => {

it('adapter.hasClass() checks classes on root', () => {
const {root, adapter} = setupTest();
expect(adapter.hasClass(CssClasses.PROCESSING))
.toBe(false, 'returns false when class does not exist');
expect(adapter.hasClass(CssClasses.PROCESSING)).toBe(
false,
'returns false when class does not exist',
);
root.classList.add(CssClasses.PROCESSING);
expect(adapter.hasClass(CssClasses.PROCESSING))
.toBe(true, 'returns true when class exists');
expect(adapter.hasClass(CssClasses.PROCESSING)).toBe(
true,
'returns true when class exists',
);
});

it('adapter.isDisabled() returns root disabled property', () => {
Expand Down

0 comments on commit 2123067

Please sign in to comment.