57 Commits

Author SHA1 Message Date
David Souther
deb3cb4dae feat(ngMock/$exceptionHandler): log errors when rethrowing
Now the `rethrow` mode will also record a log of the error in the same
way as the `log` mode.

Closes #10540
Closes #10564
2014-12-23 18:16:51 +00:00
David Souther
b43fa3bb30 test($exceptionHandlerProvider): call inject() to run tests
In the current angular-mocksSpec, the tests for $exceptionHandlerProvider
call `module` to run tests on `$exceptionHandlerProvider.mode()`, but do
not call `inject()` to pump the module definitions.

Closes #10563
2014-12-23 16:28:08 +00:00
Pawel Kozlowski
acb066e84a fix(ngMock): allow numeric timeouts in $httpBackend mock
Fixes #4891
2014-12-03 21:06:33 +01:00
Shahar Talmi
08cd5c19c7 fix(ngMock): respond did not always take a statusText argument
minor fix so that `respond` can take a `statusText` argument
even when having status 200 by default

Closes #8270
2014-11-26 20:03:23 +01:00
David Stensland
d81ff8885b fix(ngMock): call $interval callbacks even when invokeApply is false
Make ngMock.$interval behave like ng.$interval

Closes #10032
2014-11-14 11:42:24 -05:00
Henry Zhu
06016bb12c style(*): add rules requireSpace(After|Before)BinaryOperators 2014-11-09 15:51:01 +01:00
Igor Minar
74981c9f20 feat(ngMock): decorator that adds Scope#$countChildScopes and Scope#$countWatchers
When writing tests it's often useful to check the number of child scopes
or watchers within the current current scope subtree. Common use-case for advanced
directives is to test that the directive is properly cleaning up after itself. These
new methods simplify writing assertions that verify that child scopes were properly
destroyed or that watchers were deregistered.

Closes #9926
Closes #9871
2014-11-05 13:23:19 -05:00
Henry Zhu
d3b1f502e3 style(*): add rule disallowSpacesInAnonymousFunctionExpression beforeOpeningRoundBrace, including i18n generator 2014-10-23 15:59:26 -04:00
Henry Zhu
7f65f97919 style(*): add rule requireSpacesInFunction beforeOpeningCurlyBrace
This rule enforces a space after the curly brace
for function declarations, anonymous function expressions,
and named function expressions.
2014-10-23 15:59:25 -04:00
Georgios Kalpakas
9e0ab14826 test(ngMock.$httpBackend): add tests for the existence of when shortcut methods
Closes #9322
2014-10-09 14:24:56 -07:00
Lucas Galfaso
e843ae7a4c chore(IE8): remove all special code for IE8
Remove all code that was IE8 specific

Closes #8837
2014-10-06 17:04:09 -07:00
Igor Minar
1a2caad922 chore(mocks): remove helper fn angular.mocks.clearData
we don't need this any more because Karma reloads the iframe after each test run

Related to #8532
Closes #8618
2014-08-22 15:30:34 -07:00
Shahar Talmi
477626d846 feat(ngMock): allow override of when/expect definitions
Closes #5766
Closes #8352
2014-08-03 17:08:48 +01:00
Michał Gołębiowski
9e7cb3c375 feat(jQuery): upgrade to jQuery to 2.1.1
The data jQuery method was re-implemented in 2.0 in a secure way. This made
current hacky Angular solution to move data between elements via changing the
value of the internal node[jQuery.expando] stop working. Instead, just copy the
data from the first element to the other one.

Testing cache leaks on jQuery 2.x is not possible in the same way as it's done
in jqLite or in jQuery 1.x as there is no publicly exposed data storage. One
way to test it would be to intercept all places where a jQuery object is created
to save a reference to the underlaying node but there is no single place in the
jQuery code through which all element creation passes (there are various
shortcuts for performance reasons). Instead we rely on jqLite.cache testing
to find potential data leaks.

BREAKING CHANGE: Angular no longer supports jQuery versions below 2.1.1.
2014-07-31 22:20:31 +02:00
Shahar Talmi
2f0a448873 fix(injector): allow multiple loading of function modules
Change HashMap to give $$hashKey also for functions so it will be possible to load multiple module
function instances. In order to prevent problem in angular's test suite,  added an option to HashMap
to maintain its own id counter and added cleanup of $$hashKey from all module functions after each
test.

Before this CL, functions were added to the HashMap via toString(), which could potentially return
the same value for different actual instances of a function. This corrects this behaviour by
ensuring that functions are mapped with hashKeys, and ensuring that hashKeys are removed from
functions and objects at the end of tests.

In addition to these changes, the injector uses its own set of UIDs in order to prevent confusingly
breaking tests which expect scopes or ng-repeated items to have specific hash keys.

Closes #7255
2014-06-16 20:43:16 -04:00
Dave Smith
e1d6178457 fix($httpBackend): Add missing expectHEAD() method
This was documented but not implemented.

With accompanying unit test to ensure the $httpBackend.expect*() methods exist.

Closes #7320
2014-04-30 18:51:20 -04:00
Shahar Talmi
accd35b747 chore(jshint): enforce jshint for tests
Closes #7264
2014-04-27 21:20:31 +01:00
jim lyndon
1d2414ca93 feat($http): add xhr statusText to completeRequest callback
Makes xhr status text accessible is $http success/error callback.
See www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-statustext

Closes #2335
Closes #2665
Closes #6713
2014-03-27 17:08:23 -04:00
Brett Porter
0c65f1ae3e test(ngMock): workaround issue with negative timestamps
In some specific timezones and operating systems, it seems that
getTimezoneOffset() can return an incorrect value for negative timestamps, as
described in #5017. While this isn't something easily fixed in the mock code,
the tests can avoid that particular timeframe by using a positive timestamp.

Closes #5017
Closes #6730
2014-03-18 21:30:29 -07:00
Caio Cunha
d6cfcacee1 feat(ngMock.$httpBackend): added support for function as URL matcher
It's now possible to pass a function to match the URL in $httpBackend mocked
expectations. This gives a more sophisticate control over the URL matching
without requiring complex RegExp mantainance or the workaround of creating
an object with a `test` function in order to mimic RegExp interface.

This approach was suggested in [this
thread](https://groups.google.com/d/msg/angular/3QsCUEvvxlM/Q4C4ZIqNIuEJ)

Closes #4580
2014-03-18 15:19:26 -07:00
Daniel Luxemburg
dd24c78373 fix(ngMock): return false from mock $interval.cancel() when no argument is supplied
Closes #6103.
Closed #6099.
2014-02-04 16:41:25 -08:00
Wes Alvaro
3bf4390339 fix(mocks): always call functions injected with inject with this set to the current spec
Currently when a function is injected inside of a test we set the context to undefined which
is a bug.

Closes #6102
2014-02-03 22:25:30 -08:00
Vojta Jina
affcbad501 test(ngMock): fix the tests to not use global msie
My bad when merging 7e916455b3.

These tests are run with compiled Angular and then the msie is not defined.
2014-01-06 19:08:05 -08:00
Andrew C. Greenberg
7e916455b3 fix(ngMock window.inject): Remove Error 'stack' property changes
Recent browsers, particularly PhantomJS 1.9.2 and Safari 7.0
treat the stack property as non-configurable and unwritable.

Because window.inject captures the stack at the time of the inject,
and attempts to insert it into a captured throw from the injected
function by modifying e.stack, a meaningless error message and
stack is thrown instead.

This commit inserts two tests exposing the problem, and implements
a proposed solution that builds a new error-like object that mimicks
the old Error object, but with the additional stack information, and
captures the toString function from the Error object prototype.  This
appears to work for the browsers suppoerted here.
2014-01-06 17:47:06 -08:00
Karl Seamon
f69dc16241 fix(angular-mocks): use copy of mock data in $httpBackend
Copy mock data returned from the mock $httpBackend.
This prevents modifications to the response from affecting future responses.
Previously, this misbehavior was being mitigated by the deep copy in $resource, but that no longer exists.
2013-12-11 15:18:45 -08:00
Corey Burrows
4d16472b91 fix(ngMock): fixes httpBackend expectation with body object
Fixes an issue with httpBackend expectations where a given body object
may not match the actual request body if its keys are serialized in a
different order.

Closes #4956
2013-11-21 22:57:15 -08:00
Tobias Bosch
579242346c fix(tests): Correct tests for IE11
Some tests were wrong. However, src/* did not contain problems.

Fixes #5046
2013-11-21 21:53:09 -08:00
Pete Bacon Darwin
07272608d8 fix(modules): stop leaking global variables in tests
The routeUtils.js file was declaring a number of functions that were
leaking into other modules such as ngMocks causing tests to pass
incorrectly.

Closes #4360
2013-10-10 11:58:15 -07:00
Julie
2b5ce84fca feat($interval): add a service wrapping setInterval
The $interval service simplifies creating and testing recurring tasks.
This service does not increment $browser's outstanding request count,
which means that scenario tests and Protractor tests will not timeout
when a site uses a polling function registered by $interval. Provides
a workaround for #2402.

For unit tests, repeated tasks can be controlled using ngMock$interval's
tick(), tickNext(), and tickAll() functions.
2013-10-07 13:45:40 -07:00
Peter Bacon Darwin
7a586e5c19 fix(*): protect calls to hasOwnProperty in public API
Objects received from outside AngularJS may have had their `hasOwnProperty`
method overridden with something else. In cases where we can do this without
incurring a performance penalty we call directly on Object.prototype.hasOwnProperty
to ensure that we use the correct method.

Also, we have some internal hash objects, where the keys for the map are provided
from outside AngularJS. In such cases we either prevent `hasOwnProperty` from
being used as a key or provide some other way of preventing our objects from
having their `hasOwnProperty` overridden.

BREAKING CHANGE: Inputs with name equal to "hasOwnProperty" are not allowed inside
form or ngForm directives.

Before, inputs whose name was "hasOwnProperty" were quietly ignored and not added
to the scope.  Now a badname exception is thrown.

Using "hasOwnProperty" for an input name would be very unusual and bad practice.
Either do not include such an input in a `form` or `ngForm` directive or change
the name of the input.

Closes #3331
2013-10-07 09:01:13 -07:00
Vojta Jina
fc8034b352 feat(ngMock.$timeout): remove flushNext method 2013-10-02 15:59:49 -07:00
Merrick Christensen
f737c97df0 feat(ngMock): allow passing an object literal as shorthand to module 2013-09-03 14:22:12 -07:00
Igor Minar
4114f9c21b revert: feat(mocks): make $timeout#flush throw an exception when empty
This reverts commit cbf06a5d64.

This turned out to be a bad idea because it allow us to fast-forward
the wall clock time (see previous commit).
2013-08-27 17:23:36 -07:00
Igor Minar
70b44ad32a revert: fix(mocks): $timeout#flush should not update time when empty
This reverts commit 42af8eada2.

This turned out to be a bad idea as it prevents us from moving the
time forward and asserting that the component state didn't change
due to the scheduled task executing too early.
2013-08-27 17:21:11 -07:00
Igor Minar
42af8eada2 fix(mocks): $timeout#flush should not update time when empty
When $timeout#flush is called with a delay and no task can be flushed within that
delay, the current time should not be updated as that gets the mock into an inconsistent
state.

BREAKING CHANGE: if a tests was written around the buggy behavior the delays might be off now

This would typically not be a problem, but because of the previous breaking change in
$timeout.flush, the combination of two might be confusing and that's why we are documenting
it.

Old behavior:

```
doSomething(); //schedules task to execute in 500ms from now
doOtherStuff(); //schedules task to execute in 600ms from now

try {
  $timeout.flush(300); // throws "no task to be flushed" exception
} catch(e) {};
$time.flush(200); //flushes only doSomething() task
```

New behavior:

```
doSomething(); //schedules task to execute in 500ms from now
doOtherStuff(); //schedules task to execute in 600ms from now

try {
  $timeout.flush(300); // throws "no task to be flushed" exception
} catch(e) {};
$time.flush(200); // throws "no task to be flushed" exception again
                  // because previous exception didn't move the time forward
```

Fixed test:

```
doSomething(); //schedules task to execute in 500ms from now
doOtherStuff(); //schedules task to execute in 600ms from now

try {
  $timeout.flush(300); // throws "no task to be flushed" exception
} catch(e) {};
$time.flush(500); // flushes only doSomething() task
```
2013-08-25 14:46:55 -07:00
Igor Minar
cbf06a5d64 feat(mocks): make $timeout#flush throw an exception when empty
When calling $timeout.flush with or without a delay an exception should
be thrown if there is nothing to be flushed.

This prevents tests from flushing stuff unnecessarily.

BREAKING CHANGE: calling $timeout.flush(delay) when there is no task to be flushed
within the delay throws an exception now.

Please adjust the delay or remove the flush call from your tests as the exception
is a signed of a programming error.
2013-08-25 14:46:54 -07:00
Vojta Jina
b89a4e49b9 test: rename / remove duplicate unit tests 2013-08-23 12:43:42 -07:00
Ken Chen
08daa7797b feat(ngMock/$httpBackend): support a matching function for data param
Add support for passing function as validating data:
 - To avoid hacking test method of RegExp
 - Optionally overwrite `toString` method of fn to show validation tips
 - change docs: param description for `when`, `whenPost`, `whenPut`,
   `expect`, `expectPost`, `expectPut`, `expectPATCH`

Closes: #2981
2013-08-06 16:54:50 +01:00
Étienne Barrié
3079a6f4e0 fix(ngMock): keep withCredentials on passThrough
When using passThrough() and specifying withCredentials on the $http
call, the option is now passed to the underlying $httpBackend.
2013-08-01 16:07:33 -07:00
Chirayu Krishnappa
f274c0a66b fix(mock.$log): keep in sync with $log
Closes #2343
2013-07-31 13:38:24 -07:00
Matias Niemelä
462ed033d5 feat(ngMock): $timeout.flushNext can expect specific timeout delays
the $timeout mock's flush method allows flushing queued up requests
but doesn't allow to for checking with what delay a task was queued
up. flushNext flushes the next queued up task and can asserts the
scheduled delay.
2013-07-26 08:57:25 -07:00
Matias Niemelä
b7fdabc4bf feat(ngMock): support delay limit for $timeout.flush 2013-07-26 08:56:41 -07:00
Igor Minar
717f24feb4 chore(dump): remove dead code
This code is not being used any more and the test is now failing
due to Karma changes. Karma used to expose window.dump but that
changed recently and that's why our build is now failing.

I'm removing the code and test, but we still need to figure out
how to route window.dump through angular.mock.dump, but that will
have to be a separate commit.
2013-07-22 13:59:27 -07:00
Michał Gołębiowski
f1b94b4b59 feat(jqLite): switch bind/unbind to more recent jQuery on/off
jQuery switched to a completely new event binding implementation as of
1.7.0, centering around on/off methods instead of previous bind/unbind.
This patch makes jqLite match this implementation while still supporting
previous bind/unbind methods.
2013-06-19 20:53:24 +01:00
David Bennett
9f4f593711 feat($http): add support for aborting via timeout promises
If the timeout argument is a promise, abort the request when it is resolved.
Implemented by adding support to $httpBackend service and $httpBackend mock
service.

This api can also be used to explicitly abort requests while keeping the
communication between the deffered and promise unidirectional.

Closes #1159
2013-05-20 14:15:04 -07:00
Maxim Grach
df744f3af4 feat(dateFilter): add [.,]sss formatter for milliseconds
Also Implement getMilliseconds() method of TzDate and
add test for this in ngMock.
2013-02-07 02:28:33 -08:00
petrovalex
f0c6ebc076 feat($timeout-mock): add verifyNoPendingTasks method
added verifyNoPendingTasks method, which throws error if not all
deferred tasks have been flushed

Closes #1245
2012-12-20 20:39:40 +01:00
Igor Minar
9af7a9198e fix($defer): remove deprecated $defer service 2012-06-12 01:09:07 -07:00
Misko Hevery
85632cb44c feat($rootElement): added application root element
Publish the application root element as $rootElement
so that it can be injected to other services.
2012-06-02 14:50:58 -07:00
Igor Minar
4511d39cc7 feat($timeout): add $timeout service that supersedes $defer
$timeout has a better name ($defer got often confused with something related to $q) and
is actually promise based with cancelation support.

With this commit the $defer service is deprecated and will be removed before 1.0.

Closes #704, #532
2012-05-23 15:00:56 -07:00