Last active
September 25, 2015 20:00
-
-
Save lucasmazza/aaaa9dd7a9f6e645c232 to your computer and use it in GitHub Desktop.
This file contains hidden or 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($, QUnit){ | |
QUnit.assert.hasSelector = function(node, selector) { | |
var el = $('<div>' + node.outerHTML + '</div>'), | |
ok = el.has(selector); | |
this.push(ok, el.html(), selector, "expected to have selector '" + selector +"'."); | |
}; | |
QUnit.assert.hasLink = function(node, text, href) { | |
var el = $('<div>' + node.outerHTML + '</div>'), | |
anchors = el.find('a').filter(function() { | |
return this.text === text && (!href || this.href === href); | |
}); | |
this.push(!!anchors.length, el.html(), text, "expected to have link '" + text + "'('" + href + "')"); | |
} | |
QUnit.assert.hasText = function(node, selector, text) { | |
this.hasSelector(node, selector); | |
var el = $('<div>' + node.outerHTML + '</div>').find(selector); | |
if (el.length) { | |
var source = el.text(), | |
ok = el.text().includes(text); | |
this.push(ok, source, text, "expected '" + selector + "' to have contain '" + text + "', but contains '" + source + "' instead."); | |
} | |
}; | |
})(jQuery, QUnit); |
This file contains hidden or 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(QUnit, document) { | |
var React = require('react'); | |
QUnit.assert.renderComponent = function(Component, props, callback) { | |
var element = React.createElement(Component, props), | |
root = document.createElement('div'), | |
done = this.async(); | |
var instance = React.render(element, root, function() { | |
setTimeout(function() { | |
callback(root.childNodes[0], instance); | |
done(); | |
}) | |
}); | |
} | |
})(QUnit, document); |
This file contains hidden or 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
var TweetMessage = require('components/messages/tweet'); | |
QUnit.module('Components.Messages.Tweet'); | |
QUnit.test('renders the tweet message element', function(assert) { | |
var message = { author: { name: 'Test Author', avatar_url: '' }, body: 'depois de um dia meio chato\nmuito friu -- @rondi, https://twitter.com/Rondi/status/108781678809460736' }; | |
assert.renderComponent(TweetMessage, { message: message }, function(node) { | |
assert.hasSelector(node, '.chat-message-text-container'); | |
assert.hasSelector(node, 'blockquote.embedded-tweet'); | |
assert.hasText(node, 'blockquote p', 'depois de um dia meio chatomuito friu'); | |
assert.hasLink(node, 'rondi', 'https://twitter.com/rondi'); | |
assert.hasLink(node, 'https://twitter.com/Rondi/status/108781678809460736', 'https://twitter.com/Rondi/status/108781678809460736'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment