Last active
February 7, 2018 14:03
-
-
Save akc42/121c619ef2476ce82086 to your computer and use it in GitHub Desktop.
Polymer Testing
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
module.exports = function(config) { | |
config.set({ | |
// base path that will be used to resolve all patterns (eg. files, exclude) | |
basePath: '', | |
// frameworks to use | |
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | |
frameworks: ['jasmine'], | |
// list of files / patterns to load in the browser | |
files: [ | |
'polymer-setup.js', | |
'components/jasmine-ajax/lib/mock-ajax.js', | |
'client/**/*.test.js', | |
{pattern:'components/**/*',included:false,served:true}, | |
{pattern:'client/**/*',included:false,served:true} | |
], | |
// list of files to exclude | |
exclude: [ | |
], | |
// preprocess matching files before serving them to the browser | |
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | |
preprocessors: { | |
'client/**/*-fixture.html':'html2js' | |
}, | |
// test results reporter to use | |
// possible values: 'dots', 'progress' | |
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | |
reporters: ['progress'], | |
// web server port | |
port: 9876, | |
// enable / disable colors in the output (reporters and logs) | |
colors: true, | |
// level of logging | |
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | |
logLevel: config.LOG_INFO, | |
// enable / disable watching file and executing tests whenever any file changes | |
autoWatch: true, | |
// start these browsers | |
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | |
browsers: ['Chrome'], | |
// Continuous Integration mode | |
// if true, Karma captures browsers, runs the tests and exits | |
singleRun: false | |
}); | |
}; |
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
(function(){ | |
var PolymerTests = {}; | |
//I am not sure if we can just do this once, or for every test. I am hoping just once | |
var script = document.createElement("script"); | |
script.src = "/base/components/platform/platform.js"; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
var POLYMER_READY = false; | |
beforeEach(function(done){ | |
window.addEventListener('polymer-ready', function(){ | |
POLYMER_READY = true; | |
done(); | |
}); | |
if (POLYMER_READY) done(); | |
}); | |
var container; //Used to hold fixture | |
PolymerTests.loadFixture = function(fixture,done) { | |
container = document.createElement("div"); | |
container.innerHTML = __html__[fixture]; | |
document.body.appendChild(container); | |
waits(0); | |
done(); | |
}; | |
//After every test, we remove the fixture | |
afterEach(function(){ | |
document.body.removeChild(container); | |
}); | |
window.PolymerTests = PolymerTests; | |
})(); |
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
<link rel="import" href="smf-auth.html"> | |
<smf-auth id="smf-auth" login="/football/auth_json.php" fail="/football.php" splash="football.png" user> | |
<p>This text should only appear when authorised</p> | |
</smf-auth> |
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
<link rel="import" href="../../components/polymer/polymer.html"> | |
<link rel="import" href="../../components/core-ajax/core-ajax.html"> | |
<polymer-element name="smf-auth" attributes="user" login fail splash> | |
<template> | |
<core-ajax id="req" url="{{login}}" handleAs="json" on-core-response="{{handleResponse}}" | |
<img id="splash" src="{{splash}}"/> | |
<template if="{{autheticated}}"> | |
<content></content> | |
</template> | |
</template> | |
<script> | |
Polymer('smf-auth'{ | |
created:function(){ | |
this.authenticated = false; | |
this.user = {}; | |
}, | |
ready:function() { | |
this.$.req.go(); | |
}, | |
handleResponse:function(response){ | |
//TODO decide what the response is | |
} | |
}); | |
</script> | |
</polymer-element> |
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
describe('<smf-auth>',function(){ | |
beforeEach(function(done){ | |
jasmine.Ajax.install(); | |
PolymerTests.loadFixture('client/smf-auth/smf-auth-fixture.html',done); | |
}); | |
afterEach(function(){ | |
jasmine.Ajax.uninstall(); | |
}); | |
describe("The element establishes itself",function(){ | |
xit("Should display the splash image provided",function(){ | |
}); | |
xit("Should provide an Empty User object before authentication",function(){ | |
}); | |
it("Should Make an Ajax Request to the url given in the login Attribute",function(){ | |
expect(jasmine.Ajax.requests.mostRecent().url).toBe('/football/auth_json.php'); //Url declared in our fixture | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment