forked from graphql/graphiql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replace use of enzyme with react-testing-library (graphql#1144)…
… by @ryan-m-walker - added @testing-library/react to graphiql package - added @testing-libary/jest-dom to graphiql package - removed usage of ENZYM env variable in test script in graphiql packaget - removed enzyme adapter setup from enzyme.config.js file and renamed it to test.config.js - removed use of enzyme and replaced with react-testing-library in all graphiql package test files and updated tests to use react-testing-library patterns - moved mockStorage to own file so it can be reused in other test files and added other methods to it - added a CodeMirror mock to be used in tests - mocked out codemirror addon modules - moved QueryHistory tests from own file into GraphiQL.spec.js file - removed `cross-env` from test script - moved CodeMirror mock to __mock__ file Co-authored-by: Rikki Schulte <[email protected]> Co-authored-by: Rikki Schulte <[email protected]>
- Loading branch information
1 parent
5765394
commit de73d6c
Showing
14 changed files
with
692 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
function CodeMirror(node, { value, ...options }) { | ||
let _eventListeners = {}; | ||
const mockTextArea = document.createElement('textarea'); | ||
mockTextArea.className = 'mockCodeMirror'; | ||
mockTextArea.addEventListener('change', e => { | ||
_emit('change', e); | ||
}); | ||
mockTextArea.value = value; | ||
node.appendChild(mockTextArea); | ||
|
||
function _emit(event, data) { | ||
if (_eventListeners[event]) { | ||
_eventListeners[event](data); | ||
} | ||
} | ||
|
||
return { | ||
options: { | ||
...options, | ||
}, | ||
|
||
on(event, handler) { | ||
_eventListeners[event] = handler; | ||
}, | ||
|
||
off(event) { | ||
if (_eventListeners.hasOwnProperty(event)) { | ||
const updatedEventListeners = {}; | ||
for (const e in _eventListeners) { | ||
if (e !== event) { | ||
updatedEventListeners[e] = _eventListeners[e]; | ||
} | ||
} | ||
_eventListeners = updatedEventListeners; | ||
} | ||
}, | ||
|
||
getValue() { | ||
return mockTextArea.value; | ||
}, | ||
|
||
setValue(newValue) { | ||
mockTextArea.value = newValue; | ||
}, | ||
|
||
setSize() {}, | ||
|
||
emit: _emit, | ||
}; | ||
} | ||
|
||
CodeMirror.defineExtension = () => {}; | ||
CodeMirror.registerHelper = () => {}; | ||
CodeMirror.defineOption = () => {}; | ||
CodeMirror.signal = (mockCodeMirror, event, ...args) => { | ||
mockCodeMirror.emit(event, ...args); | ||
}; | ||
|
||
module.exports = CodeMirror; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.