Skip to content

Instantly share code, notes, and snippets.

@mjacobus
Last active August 29, 2015 14:07
Show Gist options
  • Save mjacobus/9f03b814f1b665dbe54f to your computer and use it in GitHub Desktop.
Save mjacobus/9f03b814f1b665dbe54f to your computer and use it in GitHub Desktop.
/*
Koine.WebComponents.FancySelect
[data-add-selected].click()
✓ transfers option from source to destination
X re-renders the compoment
Expected 2 to equal 1. (1)
Expected 1 to equal 2. (2)
Summary (1 tests failed)
X Koine.WebComponents.FancySelect [data-add-selected].click() re-renders the compoment
Expected 2 to equal 1.
Error: Expected 2 to equal 1.
at stack (file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1304)
at buildExpectationResult (file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1281)
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:473
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:271
at addExpectationResult (file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:431)
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1227
at file:///{path}/specs/Koine.WebComponents.FancySelect_spec.js:52
at attemptSync (file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1620)
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1608
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1595
Expected 1 to equal 2.
Error: Expected 1 to equal 2.
at stack (file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1304)
at buildExpectationResult (file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1281)
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:473
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:271
at addExpectationResult (file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:431)
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1227
at file:///{path}/specs/Koine.WebComponents.FancySelect_spec.js:53
at attemptSync (file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1620)
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1608
at file:///{path}/.grunt/grunt-contrib-jasmine/jasmine.js:1595
2 specs in 0.008s.
>> 1 failures
*/
describe("Koine.WebComponents.FancySelect", function () {
var subject, source, destination, sourceElement, destinationElement, container;
var initialize = function () {
source.addOptions([
source.createOption('1', 'one'),
source.createOption('2', 'two')
]);
destination.addOptions([
source.createOption('3', 'three')
]);
subject.render();
};
beforeEach(function () {
container = $('<div id="container" />');
sourceElement = document.createElement('select');
destinationElement = document.createElement('select');
$('body').append(container).append(sourceElement).append(destinationElement);
container = $('#container');
source = new Koine.Decorators.Dom.SelectDecorator(sourceElement);
destination = new Koine.Decorators.Dom.SelectDecorator(destinationElement);
subject = new Koine.WebComponents.FancySelect(
source,
destination,
container,
jQuery
);
});
describe("[data-add-selected].click()", function () {
var option;
beforeEach(function () {
initialize();
option = container.find('.source .option:last');
option.addClass('selected');
container.find('[data-add-selected]').click();
});
it("transfers option from source to destination", function () {
expect(source.getOptions().length).toEqual(1);
expect(destination.getOptions().length).toEqual(2);
});
it("re-renders the compoment", function () {
expect(container.find('.source .option').length).toEqual(1);
expect(container.find('.destination .option').length).toEqual(2);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment