AngularJS controller test failing with RequireJS |
Yes, I have found the solution.
Here is my blog post for the same.
GitHub code is here : sample
It is done through mocking the module creation.
Edit :
With code. The trick here is to initialize AngularJS like this :
define(function(){ var app = angular.module('AngularAppModule',
'ngResource']);app.lazy = app; return app;});
This will add app.lazy reference in Angular, and then RequireJS can
initialize the controllers the same way. Test-main.js file is the same. For
running Karma, test-main will load all the scripts upfront and Require will
not be intrusive. Let me know if you have further questions.
|
Why is this Model test breaking (not failing) when I run 'rake test:models'? |
The trace is telling you that you have unknown command 'i' at line 39 of
the file product_test.rb (that's what that product_test.rb:39) means.
Do you have some misplaced i somewhere on that line? It might be outside
of the snippet you quoted -- I can't tell without your line numbers.
|
Unit test thoroughness - test passing conditions as well as failing ones? |
This is a scenario where you want to use one parametrized test which gets
all 99 values as input.
Using xUnit.net, this could look like this (untested, might contain small
compilation errors):
[Fact]
public void Widget_CannotActiveWidgetIfStateIsCancelled()
{
// Arrange ...
sut.State = State.Cancelled;
Assert.False(sut.CanActivate);
}
[Theory, ValidStatesData]
public void Widget_CanActivateWidgetIfStateIsNotCancelled(State state)
{
// Arrange ...
sut.State = state;
Assert.True(sut.CanActivate);
}
private class ValidStatesDataAttribute : DataAttribute
{
public override IEnumerable<object[]> GetData(
MethodInfo methodUnderTest, Type[] parameterTypes)
{
return Enum.GetValues(typeof(State))
.Cast<State>()
|
Can protractor test a login that is not angular based |
After placing the issue on github I received the answer I was looking for.
This can be found HERE!
Protractor requires that Angular be present on the page and the way around
this is to use the driver directly. Following the link above should stear
anyone stuck on the same issue in the right direction.
Kudos to JulieMR and the others who helped out with this issue.
|
Test passing.But Test List is Failing |
If you are testing a web application, as you know telerik tests the UI
components based on the baseURL. There are 2 different locations for
settings when you are running as a test(vs running as a testList). Cross
verify the baseURL in both the settings section(if they are the same). As I
can see the error is Element Not found. Which might be coz, the
associated baseURL for that element is different.
|
Test failing ndb transaction |
From the docs:
If the function raises an exception, the transaction is immediately
aborted and NDB re-raises the exception so that the calling code sees it.
You can force a transaction to fail silently by raising the ndb.Rollback
exception (the function call returns None in this case). There is no
mechanism to force a retry.
You can raise an exception in your unittest instead of your put() routine
to simulate that event, and it should emulate the same outcome - because a
failure to put will cause the all datastore events in the transaction to
rollback anyway.
You might find these kinds of transaction exceptions:
You can receive Timeout, TransactionFailedError, or InternalError
exceptions in cases where transactions have been committed and eventually
will be applied successfully.
|
Failing rspec test |
The error message is telling you that the page does not have the selector
'div.alert.alert-success'. It looks like the error is related to this
line:
it { should have_selector('div.alert.alert-success', text:'Welcome') }`
Capybara has a nifty method called save_and_open_page that lets you inspect
the HTML file that Capybara parses. Call this method and view the source
to inspect the selector that is not working for you. If you are still
having trouble, paste the HTML that corresponds to the selector in your
question.
You should clean up the formatting of your code because it is very hard to
read with the inconsistent spacing and indentation.
|
Nokogiri scraping test failing? |
@department_hash is not defined within the scope of the test.
If you take a simple example:
require 'rspec/autorun'
@department_hash = 2
puts defined?(@department_hash)
#=> "instance-variable"
describe "Department" do
it "should scrap correct string" do
puts defined?(@department_hash)
#=> "" (ie not defined)
end
end
You can see that @department_hash is defined in the main, but it is not
defined within the test.
You need to run your app code from within the scope of the test. For
example, moving the code into the test, @department_hash will no longer be
nil.
require 'rspec/autorun'
require 'nokogiri'
require 'open-uri'
describe "Department" do
it "should scrap correct string" do
url = "http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%
|
hartl tutorial failing test at end of 9.2.1 |
You are missing a call to your signed_in_user filter on line 2 of your
users_controller.rb. You defined the filter at the end of the controller,
but you didn't call it! :)
At the very end of the tutorial, that line should look like this:
before_action :signed_in_user, only: [:index, :edit, :update, :destroy,
:following, :followers]
However since you have not created followers yet, I think it should look
something like this:
before_action :signed_in_user, only: [:index, :edit, :update, :destroy]
I have found it very useful to copy the final source of the code on my hard
drive, so I can compare my code to the original whenever I encountered a
bug while doing this book.
|
Automapper Failing Unit Test |
The problem is that you're configuring the mapping inside a test and
expecting another test to use this configuration.
Take into account they are supposed to be independent so one test can't
rely on other test execution. This is really important
You'll need to create the mapping on Mappings_ViewModel_Address_ToDTO_pass
or on a common setup.
|
What is a good way to test change of location in AngularJS E2E test |
You can try this code;
it('should redirect to /home if credentials are correct', function(){
browser().navigateTo('/login');
input('credentials.username').enter('testuser');
input('credentials.password').enter('testpass');
element('button.login').click();
browser().navigateTo('/home');
});
|
Simple HttpClient test failing on Mono |
You should almost never use async void methods and this is one reason why.
Your Main() will end before HttpClientCall() actually completes. And since
exiting from Main() terminates the whole application, nothing will get
printed.
What you should do is to change your method into async Task and Wait() for
it in your Main(). (Mixing await and Wait() can often lead to deadlocks,
but it's the right solution for console applications.)
class MainClass
{
public static void Main()
{
new Client().HttpClientCallAsync().Wait();
}
}
public class Client
{
HttpClient client = new HttpClient();
public async Task HttpClientCallAsync()
{
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await
httpClient.GetAsync("http://vendhq.com");
|
Unit Test failing when comparing two ILists |
You need to define Equals and GetHashCode for your BusinessModel class. The
default Equals implementation is reference equality, and your object
references will be different for the items in the two lists.
Alternatively you can create an IEqualityComparer<BusinessModel>
which defines equality/hash code and pass that to SequenceEquals.
|
Capybara test failing with AJAX response |
The capybara test needed to have the option js: true passed into the
descrbe block.
Here is the result:
describe "when current_user is the comment's author", js: true do
it 'should edit the comment content' do
visit post_path(commented_post)
within ("#comment-#{commented_post.comments.first.id}") do
click_on "edit"
end
fill_in 'comment_content', with: 'No, this is the best comment'
click_on 'Edit Comment'
expect(page).to have_content('No, this is the best comment')
end
end
|
py.test is failing to deal with creating files |
Oddly enough, using 'xelatex' instead of 'pdflatex' makes things work as
normal.
For any future readers - I have TeXworks installed which presumably
installed both these tools. I don't know if xelatex influences the final
pdf produced. It seems to be producing a good .pdf
Anyway, I made this answer to my own question since there doesn't seem to
be anything else coming and it certainly solved my problem.
|
Failing rspec test on silly blocks |
This doesn't work on the console neither, since n is defined within the
block scope of the repeater method. What you're seeing on the console is
the value returned by the times block, but if you inspect the value of n,
it will still be zero.
If you change your repeater method to:
def repeater(x=0)
if x == 0
return yield
else
x.times do |n|
yield
end
end
end
Then the specs will pass, since the reference to n will be given by the
calling context
|
Allowing multiple AssertionErrors before failing a test |
var found = ['Alice', 'Bob', 'John'].map(function (name) {
return pageContent.indexOf(name) >= 0;
});
assert.include(found, true);
If I may opine that your desire for a wrapper library for fuzzy asserting
sounds misguided. Your fuzzy rules and heuristics about what is a "soft" vs
"hard" assertion failure seem like a much less sensible alternative than
good old programming using the existing assertion paradigm. It's testing.
It's supposed to be straightforward and easy to reason about.
Keep in mind you can always take logic such as the above and wrap it in a
function called includesOne(pageContent, needles) so it is conveniently
reusable across tests.
|
How to get the original error from a failing JUnit test? |
One method of drilling down to the root exception is something like this:
catch(Throwable t)
{
while(t.getCause != null)
{
t = t.getCause();
}
t.printStackTrace(System.out);
}
|
Why is my intern test failing with "document is not defined" |
It looks like you’re trying to load some code using the Node.js client
that requires a browser environment. This won’t work. You should only
load the ev/tests/FilterGrid test suite in a browser. You can do this by
modifying your Intern configuration file to look something like this:
define([ 'intern/node_modules/dojo/has' ], function (has) {
var suites = [];
if (has('host-browser')) {
suites.push('ev/tests/FilterGrid');
}
return {
// ...your existing configuration...
suites: suites,
// ...
};
});
|
Simple Channel API Related Test Failing with 1.8.2 Upgrade |
I logged this as an issue on the Google App Engine SDK issue tracker.
The issue I logged is mentioned in the original comments.
The issue was accepted and is scheduled to be fixed in the next (1.8.3)
release of the Google App Engine SDK.
Thanks for reading.
|
Why is my test failing because of inclusion error for a date range? |
The shoulda matchers check the error message in addition to the range of
values. If you look at the implementation at the link you posted, you'll
see that both the low and high message default to :inclusion (the symbol
used for looking up the internationalized version of the standard rails
error message).
The error message check in the allow value matcher allows the expected
message to be specified as a symbol, a regexp, or a string.
You're also using a different range in your validation than you are in your
test (a range of dates vs a range of ints). I believe your test will pass
if you change it to:
it { should
ensure_inclusion_of(:birthday).in_range(Date.new(1850)..Time.now.years_ago(13).to_date).with_message(/must
be at least 13/) }
|
Rspec test failing: creating new record rather than using existing one |
You're mixing acceptance specs and request specs here. @roll will not be
modified when you perform capybara requests (via fill_in, etc).
Acceptance specs test the contents of the response. Request specs test
operations on records for a given request. You might consider splitting up
your tests like so:
# Acceptance test
describe "when visiting roll call with no notes" do
before do
login_as_sensei
@dojo = FactoryGirl.create(:dojo, name: "Melbourne")
@time = FactoryGirl.create(:times, dojo: @dojo)
@roll = FactoryGirl.create(:roll_call)
visit time_roll_calls_path("melbourne", "14-2-2013", "1000")
end
it { should_not have_content("This is a note!") }
describe "and filling in note information correctly" do
before do
fill_in "roll_call[notes]", with: "Thi
|
Rspec test failing for POST member route |
The id parameter is the id of the answer:
post :vote, id: @answer.id
You might also need to pass the value parameter (maybe an 'up' or 'down'
value?).
There may be other reasons for the test to fail, e.g. validations in the
Vote model. If vote.save returns false then check the errors collection.
Following comments:
You need to pass the value as a param to post in your spec. It also seems
you have a duplicate vote, you probably don't need to create @vote in your
spec at all. The errors collection is populated by the valid? method which
is called by save.
|
how to test angularjs app with angularjs e2e with multiple inputs with same ng-model |
I figured it out. i need to use using to focus the scope. example
using('div[filter="search.username"]').input("filter").enter("foo");
using('div[filter="search.ami"]').input("filter").enter("bar")
|
failing to insert data into sqlite database via test case iOS |
On iOS, you should consider using CoreData rather than using SQLite
directly. CoreData, by default, persists to SQLite and it has much more
friendly documentation. Also, since CoreData is not a C API, it will
interoperate more nicely with the rest of your Objective-C code. There's
also nice Xcode integration when using CoreData, which will let you define
schemas easily. You'll also avoid, in many cases, writing SQL queries.
For comparisons between the two see this related question.
|
Rspec validates_uniqueness_of test failing with additional validation errors |
It's failing because you're not testing @answer. You're not defining your
subject in these tests. So it's using rspec's subject which by default is
going to a new instance of whatever class you're describing, ie.
Answer.new. You either need to explicitly set the subject to @answer or
explicitly test @answer.
describe Answer do
it { should
validate_uniqueness_of(:correct).scoped_to(:question_id).with_message("correct
You can only have 1 correct answer per question (true)") }
it { should
validate_uniqueness_of(:user_id).scoped_to(:question_id).with_message("user_id
Only 1 answer per question per user (1)") }
end
|
Rails 4 rspec test failing on numericality only_integer on boolean value? |
The spec is correct. 1 is truthy (the only non-truthy values in Ruby are
false and nil), but it is not a boolean. Booleans are not numeric; they are
their own type. A numericality validation will validate that the type is
actually numeric, and boolean is not numeric.
> true.class
=> TrueClass
> 1.class
=> Fixnum
What you probably want instead, though, is a validation that tests for a
boolean value:
validates :is_foo, inclusion => {:in => [true, false]}
|
AngularJS Failing To Compile with Google Closure App + Ant |
int is an ecmascript 3 reserved word. You'll need to use the --language_in
option of the compiler to specify one of the two ecmascript 5 options.
Newer compiler builds use ecmascript 5 as the default language.
|
Failing a scalatest when akka actor throws exception outside of the test thread |
Other than examining the logs, I can think of two ways to fail tests when
an actor crashes:
Ensure that no Terminated message is received
Check the TestActorRef.isTerminated property
The latter option is deprecated, so I'll ignore it.
Watching Other Actors from Probes describes how to setup a TestProbe. In
this case it might look something like:
val probe = TestProbe()
probe watch ref
// Actual test goes here ...
probe.expectNoMessage()
If the actor dies due to an exception it will generate the Terminated
message. If that happens during the test and you expect something else, the
test will fail. If it happens after your last message expectation, then the
expectNoMessage() should fail when Terminated is received.
|
Hartl RoR Tutorial Chapter 5 Exercise 1: Failing test: it_should_behave_like and should_not have_title |
Try updating Capybara to the version 2.1.0 in your Gemfile. have_title is
one of the new selectors.
Check out this answer for more information
|
How do you test AngularJS cookies in an end-to-end test? |
It seems like you need to use PhantomJS.
PhantomJS is a headless WebKit scriptable with a JavaScript API. It
has fast and native support for various web standards: DOM handling,
CSS selector, JSON, Canvas, and SVG. --PhantomJS website
It has support for custom cookies in its API.
In terms of testing, this is probably your best choice.
You might also want to look at CasperJS to help test page navigation.
|
button_to form submittal working in browser but failing rspec/capybara test with routing error |
You want a regular submit tag.
If using a form helper block:
<%= f.submit "RSVP Now" %>
Or use the standalone tag helper:
<%= submit_tag "RSVP Now" %>
Read the documentation on how button_to works. It is mainly used as links
that should POST, such as actions that change data in some way. It is not
for use with normal forms.
|
post create test for user count failing. Should be changed by 1, but was changed by 0 |
Your test involves creating a second user with FactoryGirl, but the
creation of the second user is failing because the email is the same as the
first and you have a uniqueness validation on that attribute.
You can either not create the first user at all or you'll need to make the
emails different (e.g. by passing in an email parameter to your FactoryGirl
call or changing the Factory to make each email address unique).
|
AngularJS Test Controller Containing routeChangeSuccess |
You're doing a great job here in your tests already. I assume your tests
are running correctly (apart from the last test) and will answer your 2
questions separately:
$routeChangeSuccess: there is no need for you to test core AngularJS
functionality. When you depend on $routeChangeSuccess to run your code at a
certain moment, it is the responsibility of the AngularJS team and their
test suite to ensure that $routeChangeSuccess works correctly.
getMenuOptions(): since this method is part of a service you are injecting,
you can create a separate unit test that tests the NavList service and move
the last test to that suite. Since you are unit testing, it is a good
practice to create a separate test suite for each component (controller,
service, etc) to keep things well organized and compact
|
How to test an AngularJS provider configuration? |
Here's the answer provided by Mark Gemmill based on Eitan Peer's answer to
my same question posted in the AngularJS Google Groups.
|
How do I test AngularJS controllers using RequireJS? |
Try this. I think you need to get rid off the function wrapping the
inject().
define(['app', 'angular', 'angularResource', 'angularMocks'], function () {
describe('App module tests', function () {
var module, $rootScope, scope, AppCtrl;
beforeEach(angular.module("MyApp"));
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
AppCtrl = $controller('AppCtrl', {
$scope: scope
});
}));
});
});
Editied:
I think you need ANGULAR_SCENARIO_ADAPTER to work with karma.
|
Exchanging module values in AngularJS test |
You can use $provide.value('name', 'Bob'); to inject the value.
var myApp = angular.module('myApp', []);
myApp.factory('greet', function (name) {
return function () {
return 'Hi ' + name + '!';
}
});
myApp.value('name', 'example');
describe('myApp', function () {
beforeEach(angular.mock.module('myApp'));
it('should say "Bob"', function () {
module(function ($provide) {
$provide.value('name', 'Bob');
});
angular.mock.inject(function ($injector) {
var greet = $injector.get('greet');
expect(greet()).toBe('Hi Bob!');
})
});
it('should say "Bar"', function () {
module(function ($provide) {
$provide.value('name', 'Bar');
});
angular.mock.inject(function ($
|
How to trigger ng-change in directive test in AngularJS |
From your explanatory comment:
All I want to do in directive's test is to check that doIt is called when
user changes the input.
Whether or not the expression indicated by ng-change is correctly evaluated
or not is really the responsibility of the ngModel directive, so I'm not
sure I'd test it in this way; instead, I'd trust that the ngModel and
ngChange directives have been correctly implemented and tested to call the
function specified, and just test that calling the function itself affects
the directive in the correct manner. An end-to-end or integration test
could be used to handle the full-use scenario.
That said, you can get hold of the ngModelController instance that drives
the ngModel change callback and set the view value yourself:
it('trigger doIt', function() {
var n
|
EmberJS unit test compared to AngularJS |
I've found unit testing in Ember to be relatively straightforward.
The are two things to make sure you understand in order to be successful
writing Ember unit tests.
First, you will sometimes need to provide an object with a container (e.g.
an Ember.DefaultContainer instance) when you create it for testing. The
container is the crux of Ember's dependency injection mechanisms.
Definitely need to learn about it.
Second, you will need to understand the Ember run loop in order to make
sure the changes you make in your unit tests will propagate (e.g. computed
properties with dependent keys becoming invalidated) before you assert that
the new value is what you expect.
I would highly recommend reviewing the unit tests for Ember itself. You
will find many useful techniques there.
|
How do I test Angularjs factory stubbing $http? |
The $httpBackend.flush() method works only for requests expectations like
expectGET.
The whenGET method allows you to mock the backend and hijack the request to
respond something special but it's doesn't count for the flush.
If you call flush() without expectations, it throws the error you're
encountering.
|