konocha 3.2.3, rails 4.0.2. I want to stub didInsetElement method in my Ember View
I use
sinon.stub(App.ToyBoxView, "didInsertElement")
but I get
TypeError: Attempted to wrap undefined property didInsertElement as function
at Object.wrapMethod (http://localhost:3500/assets/sinon.js?body=1:522:23)
at Object.stub (http://localhost:3500/assets/sinon.js?body=1:1662:22)
at Context.<anonymous> (http://localhost:3500/assets/aptp/routes/application_route_spec.js?body=1:12:22)
at invoke (http://localhost:3500/assets/ember-mocha-adapter.js?body=1:60:8)
at Context.<anonymous> (http://localhost:3500/assets/ember-mocha-adapter.js?body=1:52:11)
at Hook.Runnable.run (http://localhost:3500/assets/mocha.js:4319:15)
at next (http://localhost:3500/assets/mocha.js:4609:10)
at http://localhost:3500/assets/mocha.js:4626:5
at timeslice (http://localhost:3500/assets/mocha.js:5733:27)
my View:
App.ToyBoxView = Ember.View.extend Ember.ViewTargetActionSupport,
properties..
didInsertElement: ->
console.log "Something"
You need to define didInsertElement on App.ToyBoxView and it only exists on instances, not on the type definition itself.
Related
How do i test for a class that some method doesn't exists NoSuchMethodError Exists?
something like the below example.
expect(1.leftShift(12), NoSuchMethodError);
You can test this like you would any other error. You can pass in a function that throws the error into expect and check that it throws the right error:
const dynamic x = 'hello';
expect(() => x.notAMethod(), throwsA(isA<NoSuchMethodError>()));
Note that you will need to make your receiver (the object you are calling the method on) to be dynamic to suppress the static error that would otherwise catch this error.
I'm using RSpec 3.2.0 and I have this test:
it "has a webhook_payload method" do
Project.subclasses.each { |project_class|
expect(project_class.method_defined? :webhook_payload).to be true, "#{project_class} is a Project subclass that does not have a required 'webhook_payload' method defined."
}
end
When I run this, it gives me this error:
Failure/Error: expect(project_class.method_defined? :webhook_payload).to be true, "#{project_class} is a Project subclass that does not have a required 'webhook_payload' method defined."
ArgumentError:
wrong number of arguments (2 for 1)
I found this documentation on how to use custom error messages, and unless I have a typo, I feel like I'm following the instructions correctly: https://www.relishapp.com/rspec/rspec-expectations/v/3-2/docs/customized-message
How do I print a custom message when this test fails?
Also, I'm very new to ruby and rspec. If there's a more idiomatic way to write this test, please let me know.
It thinks your message is a second argument to the be method, instead of to the to method.
Wrap true in parentheses and it should work, or just use be_true as the other answer suggests.
expect(project_class.method_defined? :webhook_payload).to be(true), "#{project_class} is a Project subclass that does not have a required 'webhook_payload' method defined."
It should be be_true
it "has a webhook_payload method" do
Project.subclasses.each { |project_class|
expect(project_class.method_defined? :webhook_payload).to be_true, "#{project_class} is a Project subclass that does not have a required 'webhook_payload' method defined."
}
end
i excute the following code via grails console instead of BootStrap :
class BootStrap {
def fixtureLoader
def init = { servletContext ->
fixtureLoader.load("MockRecords")
}
}
I get the following error :
java.lang.NullPointerException: Cannot invoke method load() on null object
at Script1.run(Script1.groovy:16)
at org.grails.plugins.console.ConsoleService.eval(ConsoleService.groovy:57)
at org.grails.plugins.console.ConsoleService.eval(ConsoleService.groovy:37)
at org.grails.plugins.console.ConsoleController$_closure2.doCall(ConsoleController.groovy:61)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:679)
undefined
How can i use console to load fixtures
More easy ,
Without using getBean:
ctx.fixtureLoader.load("MockRecords")
it works.
DI(dependency injection) is done automatically in grails through the pattern CoC.
So if you copy / paste the code, the console will not inject the dependency. So it must be injected manually by calling the foctory ctx.getBean ('')
def fixtureLoader=ctx.getBean('fixtureLoader');
fixtureLoader.load("MockRecords")
Currently playing with John Papa's Hot Towel, I am currently having a strange error:
TypeError: Object [object Object] has no method 'isPartial'
I have been looking into this isPartial thing but without success.
All I've done is create a new kind of entity.
I don't know if I should provide more information for this problem.
Please help!
Thanks :)
Here's the full error below:
"TypeError: Object [object Object] has no method 'isPartial'
at proto.setProperty (http://localhost:13763/scripts/breeze.debug.js:13153:31)
at http://localhost:13763/scripts/breeze.debug.js:5833:30
at Object.objectForEach (http://localhost:13763/scripts/breeze.debug.js:311:17)
at proto.createEntity (http://localhost:13763/scripts/breeze.debug.js:5832:22)
at proto.createEntity (http://localhost:13763/scripts/breeze.debug.js:9876:18)
at dtoToEntityMapper (http://localhost:13763/App/services/breeze.partial-entities.js:32:38)
at Array.map (native)
at Object.mapDtosToEntities (http://localhost:13763/App/services/breeze.partial-entities.js:23:25)
at querySucceeded (http://localhost:13763/App/services/datacontext.js:64:42)
From previous event:
at Object.getMyEntities (http://localhost:13763/App/services/datacontext.js:60:18)
at Object.activate (http://localhost:13763/App/viewmodels/home.js:6:32)
at activate (http://localhost:13763/App/durandal/viewModel.js:74:38)
at Object.<anonymous> (http://localhost:13763/App/durandal/viewModel.js:231:37)
at Object.<anonymous> (http://localhost:13763/scripts/jquery-1.9.1.min.js:3:9221)
at c (http://localhost:13763/scripts/jquery-1.9.1.min.js:3:7857)
at Object.p.add [as done] (http://localhost:13763/scripts/jquery-1.9.1.min.js:3:8167)
at Array.<anonymous> (http://localhost:13763/scripts/jquery-1.9.1.min.js:3:9198)"
Would need more info to diagnose. Is the new type in metadata? Did you create a custom constructor for your type that defines isPartial, as CCJS does in model.js ~ln #36?
// Pass the Type, Ctor (breeze tracks properties created here), and initializer
metadataStore.registerEntityTypeCtor(
'Session', function () { this.isPartial = false; }, sessionInitializer);
You can find out if you've successfully added a property to a type by following this example based on a test method in "entityExtensionTests" of the DocCode sample:
function assertFooPropertyIsUnmappedPropertyOfCustomer(manager) {
var custType = manager.metadataStore.getEntityType("Customer");
var fooProp = custType.getDataProperty('foo');
ok(fooProp && fooProp.isUnmapped,
"'foo' property should be defined as unmapped property after registration.");
}
Btw, in the forthcoming Breeze v.1.3.2 there is much easier way to map partials - flat projections like these - into an EntityType using EntityQuery.toType(). You would still need to add isPartial to the type.
I had same issue and I needed to clear my browser cache as it had not got my updated model.js file in which I'd just added a new metadataStore.registerEntityTypeCtor for an entity.
I'm currently calling a jQuery based plugin called Bootstrap Context Menu.
In order to call it, I need to use the Javascript Interop library. But when I call a jQuery method from it I receive the following warning:
The method 'jQuery' is not defined for the class 'Proxy'
Code snippet:
js.scoped(() {
js.context.jQuery('#canvas').contextmenu();
});
This was not happening before some dart/js-interop updates. What is the right way to get rid of this warning?
You get this warning because the new analyzer doesn't seem to be aware of the option Report 'no such member' warnings when class defines noSuchMethod() ( Reported at http://dartbug.com/10016 ). If you switch back to the legacy analyzer you shouldn't see this warning anymore.
That said if you want to use the new analyzer and get rid of this warning you can use the array notation like this :
js.context["jQuery"]('#canvas')["contextmenu"]();
But :
it's less readable particullary for method calls.
it's less efficient for method calls because 2 operations are done ( f = js.context["jQuery"] followed by f('#canvas') ) instead of 1 ( js.context.jQuery('#canvas') )