Skip to content

Commit

Permalink
WIP: Fix remaining unit test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
acdvorak committed Feb 8, 2019
1 parent cb8620a commit 3e01b8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/mdc-textfield/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ class MDCTextFieldFoundation extends MDCFoundation<MDCTextFieldAdapter> {
* @return The native text input from the host environment, or a dummy if none exists.
*/
private getNativeInput_(): HTMLInputElement | NativeInputType {
return this.adapter_.getNativeInput() || {
// adapter_ can be undefined in foundation unit tests. This happens when testdouble is creating a mock object and
// invokes the shouldShake/shouldFloat getters (which in turn call getValue(), which calls this method) before
// init() has been called in the MDCTextField constructor.
const nativeInput = this.adapter_ ? this.adapter_.getNativeInput() : null;
return nativeInput || {
disabled: false,
maxLength: -1,
type: 'input',
Expand Down
12 changes: 6 additions & 6 deletions test/unit/mdc-textfield/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ test('defaultAdapter returns a complete adapter implementation', () => {
]);
});

const setupTest = () => {
const setupTest = ({characterCounter = false} = {}) => {
const mockAdapter = td.object(MDCTextFieldFoundation.defaultAdapter);
const helperText = td.object({
setContent: () => {},
showToScreenReader: () => {},
setValidity: () => {},
});
const characterCounter = td.object({
characterCounter = characterCounter === true ? td.object({
setCounterValue: () => {},
});
}) : undefined;
const leadingIcon = td.object({
setDisabled: () => {},
setAriaLabel: () => {},
Expand Down Expand Up @@ -866,7 +866,7 @@ test('#handleInput activates focus state', () => {
});

test('#handleInput updates character counter on text input', () => {
const {foundation, mockAdapter, characterCounter} = setupTest();
const {foundation, mockAdapter, characterCounter} = setupTest({characterCounter: true});

const nativeInput = {
type: 'text',
Expand All @@ -884,7 +884,7 @@ test('#handleInput updates character counter on text input', () => {


test('#handleInput throws error when maxLength HTML attribute is not found in input element', () => {
const {foundation, mockAdapter} = setupTest();
const {foundation, mockAdapter} = setupTest({characterCounter: true});

const nativeInput = {
type: 'text',
Expand All @@ -901,7 +901,7 @@ test('#handleInput throws error when maxLength HTML attribute is not found in in

test('#handleValidationAttributeChange sets character counter when maxlength attribute value is changed in input ' +
'element', () => {
const {foundation, mockAdapter, characterCounter} = setupTest();
const {foundation, mockAdapter, characterCounter} = setupTest({characterCounter: true});

const nativeInput = {
type: 'text',
Expand Down

0 comments on commit 3e01b8c

Please sign in to comment.