From 7720dbbd4ed5379d6d06e56f92a940c0c7a546a5 Mon Sep 17 00:00:00 2001 From: Jed Watson Date: Wed, 13 Sep 2017 01:04:56 +1000 Subject: [PATCH] Fix linter issues and tests for Async --- src/Async.js | 10 ++++------ test/Async-test.js | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Async.js b/src/Async.js index 7cb4707132..af7daed867 100644 --- a/src/Async.js +++ b/src/Async.js @@ -68,10 +68,6 @@ export default class Async extends Component { } } - componentWillUnmount () { - this._callback = null; - } - componentWillReceiveProps(nextProps) { if (nextProps.options !== this.props.options) { this.setState({ @@ -80,6 +76,10 @@ export default class Async extends Component { } } + componentWillUnmount () { + this._callback = null; + } + clearOptions() { this.setState({ options: [] }); } @@ -92,7 +92,6 @@ export default class Async extends Component { cache && cache.hasOwnProperty(inputValue) ) { - console.log(`loadOptions returning with cache:`, cache[inputValue]); this.setState({ options: cache[inputValue] }); @@ -139,7 +138,6 @@ export default class Async extends Component { } onInputChange (inputValue) { - const { ignoreAccents, ignoreCase, onInputChange } = this.props; let transformedInputValue = inputValue; diff --git a/test/Async-test.js b/test/Async-test.js index bc14f00c03..3e76e9fc15 100644 --- a/test/Async-test.js +++ b/test/Async-test.js @@ -386,26 +386,30 @@ describe('Async', () => { }); describe('if noResultsText has been provided', () => { - it('returns the noResultsText', () => { - asyncInstance.select = { state: { inputValue: 'asdf' } }; - expect(asyncInstance.noResultsText(), 'to equal', 'noResultsText'); + it('returns the noResultsText', (cb) => { + asyncInstance.setState({ + inputValue: 'asfd', + }, () => { + expect(asyncInstance.noResultsText(), 'to equal', 'noResultsText'); + cb(); + }); }); }); describe('if noResultsText is empty', () => { - beforeEach((cb) => { + beforeEach(() => { createControl({ searchPromptText: 'searchPromptText', loadingPlaceholder: 'loadingPlaceholder' }); - asyncInstance.setState({ - isLoading: false, - inputValue: 'asdfkljhadsf' - }, cb); }); - it('falls back to searchPromptText', () => { - asyncInstance.select = { state: { inputValue: 'asdf' } }; - expect(asyncInstance.noResultsText(), 'to equal', 'searchPromptText'); + it('falls back to searchPromptText', (cb) => { + asyncInstance.setState({ + inputValue: 'asfd', + }, () => { + expect(asyncInstance.noResultsText(), 'to equal', 'searchPromptText'); + cb(); + }); }); }); });