Skip to content

Commit

Permalink
Add positive tests for sending/recieving to/from a specific domain
Browse files Browse the repository at this point in the history
  • Loading branch information
bluepnume committed Mar 23, 2017
1 parent 239c7a0 commit 0090305
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,6 @@ after(function() {

describe('[post-robot] happy cases', function() {

it('should allow an iframe dom element in send function', function() {

return postRobot.send(frameElement, 'setupListener', {

messageName: 'foo',
data: {
foo: 'bar'
}

}).then(function() {

return postRobot.send(frameElement, 'foo').then(function({ data }) {
assert.equal(data.foo, 'bar');
});
});
});

it('should set up a simple server and listen for a request', function(done) {

postRobot.on('foobu', function() {
Expand Down Expand Up @@ -154,6 +137,35 @@ describe('[post-robot] happy cases', function() {
});
});
});

it('should set up a simple server and listen for a request from a specific domain', function(done) {

postRobot.on('domainspecificmessage', { domain: 'mock://test-post-robot-child.com' }, function() {
done();
});

postRobot.send(childFrame, 'sendMessageToParent', {
messageName: 'domainspecificmessage'
}).catch(done);
});


it('should message a child with a specific domain and expect a response', function() {

return postRobot.send(childFrame, 'setupListener', {

messageName: 'domainspecificmessage',
data: {
foo: 'bar'
}

}, { domain: 'mock://test-post-robot-child.com' }).then(function() {

return postRobot.send(childFrame, 'domainspecificmessage').then(function({ data }) {
assert.equal(data.foo, 'bar');
});
});
});
});


Expand All @@ -176,6 +188,23 @@ describe('[post-robot] options', function() {
});
});

it('should work when referencing the child by element reference', function() {

return postRobot.send(frameElement, 'setupListener', {

messageName: 'foo',
data: {
foo: 'bar'
}

}).then(function() {

return postRobot.send(frameElement, 'foo').then(function({ data }) {
assert.equal(data.foo, 'bar');
});
});
});

it('should be able to listen for a message only once', function() {

var count = 0;
Expand Down

0 comments on commit 0090305

Please # to comment.