Skip to content

Instantly share code, notes, and snippets.

@derpixler
Last active August 28, 2019 04:06
Show Gist options
  • Save derpixler/744d6785eded62e1082cdebdefa05922 to your computer and use it in GitHub Desktop.
Save derpixler/744d6785eded62e1082cdebdefa05922 to your computer and use it in GitHub Desktop.
{
"name": "@derpixler/jest-prototype-tests",
"version": "1.0.0",
"description": "",
"main": "the-prototype.js",
"scripts": {
"test": "jest"
},
"jest": {
"verbose": true,
"setupFiles": []
},
"author": {
"name": "René Reimann",
"email": "[email protected]",
"url": "http://www.rene-reimann.de"
},
"license": "MIT",
"devDependencies": {
"eslint": "^5.16.0",
"eslint-config-google": "^0.13.0",
"jest": "^24.8.0"
}
}
var myFunction = function(arg1, arg2) {
this.options = {};
this.testNodes = [];
this.options.arg1 = arg1;
this.options.arg2 = arg2;
this.fooBar();
this.testFunction();
};
myFunction.prototype = {
testFunction: function(){
this.options.arg3 = 'abc';
},
};
myFunction.prototype.fooBar = function(){
const nodes = document.querySelectorAll('body span');
nodes.forEach(node => {
this.testNodes.push(node.innerHTML);
});
};
module.exports = myFunction;
var myFunction = require('./prototype');
beforeEach( () => {
document.body.innerHTML =
'<div>' +
' <span id="username">FOObar</span>' +
' <button id="button" />' +
'</div>';
this.myFunc = new myFunction();
} );
describe('Prototype Test', () => {
test( 'call', () => {
const testNodes = this.myFunc.testNodes;
expect(Array.isArray(testNodes) && testNodes.length > 0).toBe(true);
testNodes.map(node =>{
expect(node).toBe('FOObar');
});
} );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment