From e498ef0ff9c8ec1d68a93a7c9a69ab33e17123d5 Mon Sep 17 00:00:00 2001 From: Vit Brunner Date: Sun, 21 Dec 2014 21:48:56 +0100 Subject: [PATCH] Simplify tests --- source/tests/services/poems.js.coffee | 5 +--- source/tests/services/route.js.coffee | 35 ++++++++++----------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/source/tests/services/poems.js.coffee b/source/tests/services/poems.js.coffee index 5d5d739..b85353e 100644 --- a/source/tests/services/poems.js.coffee +++ b/source/tests/services/poems.js.coffee @@ -2,10 +2,7 @@ poems = {} module "poems", { setup: () -> - angular.module("sideBySide").service("route", () -> - @params = { 'display': 'asdf' } - ) - poems = angular.injector(['ng', 'sideBySide']).get('poems') + poems = injector.get('poems') } setPoems = () -> diff --git a/source/tests/services/route.js.coffee b/source/tests/services/route.js.coffee index fd1b418..0bc76f2 100644 --- a/source/tests/services/route.js.coffee +++ b/source/tests/services/route.js.coffee @@ -2,24 +2,25 @@ route = {} module "route", {} -simpleSetup = () -> +setup = ( + base = 'http://example.com' + path = '/asdf:zxcv/qwerty:asdf' + hash = '#test' +) -> angular.module("sideBySide").service("$location", () -> - @path = () -> - '/asdf:zxcv/qwerty:asdf' - @url = () -> - '/asdf:zxcv/qwerty:asdf#test' - @absUrl = () -> - 'http://example.com/asdf:zxcv/qwerty:asdf#test' + @path = () -> path + @url = () -> path + hash + @absUrl = () -> base + path + hash @ ) route = angular.injector(['ng', 'sideBySide']).get('route') test "has app url", () -> - simpleSetup() + setup() equal route.appUrl, 'http://example.com' test "gets parameters", () -> - simpleSetup() + setup() deepEqual route.params, { 'asdf': 'zxcv' 'qwerty': 'asdf' @@ -27,7 +28,7 @@ test "gets parameters", () -> } test "updates parameters", () -> - simpleSetup() + setup() route.update('asdf', 'hjkl') deepEqual route.params, { 'asdf': 'hjkl' @@ -36,7 +37,7 @@ test "updates parameters", () -> } test "adds parameter", () -> - simpleSetup() + setup() route.update('new', 'one') deepEqual route.params, { 'asdf': 'zxcv' @@ -46,17 +47,7 @@ test "adds parameter", () -> } test "gets arrays", () -> - angular.module("sideBySide").service("$location", () -> - urlPath = '/display:Language:Czech,English' - @path = () -> - urlPath - @url = () -> - urlPath - @absUrl = () -> - 'http://example.com/' + urlPath - @ - ) - route = angular.injector(['ng', 'sideBySide']).get('route') + setup('http://example.com', '/display:Language:Czech,English', '') deepEqual route.params, { 'base': ''