Skip to content

Split publishEvent to broadcastEvent and emitEvent #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion angular-test-runner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ declare namespace angularTestRunner {
navigateTo: (url: string) => IAction;
expectElement: (selector: string) => Matchers;
listenTo: (eventName: string, handler: (data: any) => void) => IAction;
publishEvent: (eventName: string, data: any) => IAction;
broadcastEvent: (eventName: string, data: any) => IAction;
emitEvent: (eventName: string, data: any) => IAction;
}

interface Matchers {
Expand Down
20 changes: 13 additions & 7 deletions angular-test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -26941,12 +26941,17 @@ function listenTo(event, handler) {
});
};
}
function publishEvent(event, data) {
return function($el) {
angular.element($el).scope().$broadcast(event, data);
};
}
function broadcastEvent(event, data) {
return function($el) {
angular.element($el).scope().$broadcast(event, data);
};
}

function emitEvent(event, data) {
return function($el) {
angular.element($el).scope().$emit(event, data);
};
}
function wait(timeout) {
return function () {
return {
Expand Down Expand Up @@ -27051,7 +27056,8 @@ module.exports = {
apply: apply,
expectElement: expectElement,
listenTo: listenTo,
publishEvent: publishEvent
broadcastEvent: broadcastEvent,
emitEvent: emitEvent
};


Expand Down Expand Up @@ -27225,4 +27231,4 @@ function wrap(req) {
}

},{"lodash":2}]},{},[5])(5)
});
});
11 changes: 9 additions & 2 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ function listenTo(event, handler) {
});
};
}
function publishEvent(event, data) {
function broadcastEvent(event, data) {
return function($el) {
angular.element($el).scope().$broadcast(event, data);
};
}

function emitEvent(event, data) {
return function($el) {
angular.element($el).scope().$emit(event, data);
};
}

function wait(timeout) {
return function () {
return {
Expand Down Expand Up @@ -165,6 +171,7 @@ module.exports = {
apply: apply,
expectElement: expectElement,
listenTo: listenTo,
publishEvent: publishEvent
broadcastEvent: broadcastEvent,
emitEvent: emitEvent
};

31 changes: 26 additions & 5 deletions test/sample-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('sample test', function () {
name: '='
},
controllerAs: 'vm',
controller: function ($http, $scope, $timeout) {
controller: function ($http, $scope, $timeout, $rootScope) {
this.sayHello = function () {
$http.post('/greeting', {name: $scope.name})
.then(function (response) {
Expand All @@ -32,7 +32,11 @@ describe('sample test', function () {
$scope.$emit('greeting', $scope.name);
};

$scope.$on('externalGreeting', function(event, greeting) {
$scope.$on('broadcastedGreeting', function(event, greeting) {
$scope.message = greeting;
});

$rootScope.$on('emitedGreeting', function(event, greeting) {
$scope.message = greeting;
})
},
Expand All @@ -55,7 +59,8 @@ describe('sample test', function () {
var mouseover = testRunner.actions.mouseover;
var mouseleave = testRunner.actions.mouseleave;
var listenTo = testRunner.actions.listenTo;
var publishEvent = testRunner.actions.publishEvent;
var broadcastEvent = testRunner.actions.broadcastEvent;
var emitEvent = testRunner.actions.emitEvent;

beforeEach(function () {

Expand Down Expand Up @@ -191,14 +196,14 @@ describe('sample test', function () {
expect(greeted).toEqual('John');
});

it('allows event publishing', function () {
it('allows to broadcast event', function () {

// given:
var html = app.runHtml('<greeting/>', {});

// when:
html.perform(
publishEvent('externalGreeting', 'Hello, Jimmy!')
broadcastEvent('broadcastedGreeting', 'Hello, Jimmy!')
);

// then:
Expand All @@ -207,5 +212,21 @@ describe('sample test', function () {
);
});

it('allows to emit event', function () {

// given:
var html = app.runHtml('<greeting/>', {});

// when:
html.perform(
emitEvent('emitedGreeting', 'Hello, Jonny!')
);

// then:
html.verify(
expectElement('.greeting').toContainText('Hello, Jonny!')
);
});


});