I am new to Cypress, I am trying to use fixtures in my code, and keep getting ReferenceError if I used it aliasname.variablename fashion.
describe('Fixture Demo', function() {
it('This works', function() {
cy.fixture('admindetails').then((user) => {
cy.log(user.username)
})
})
it('This does not work', function() {
cy.fixture('admindetails').as(user)
cy.log(user.username)
})
})
I included both what is working and what is not. My question is how can I simple use user.username using alias? I even tried #user.username and it doesn't work. I am trying to make 2nd test work. Any help would be highly appreciated. Thanks in advance.
Your second test case isn't a valid way to do this, your first test is the correct way.
user is just a normal Javascript variable. In your second test, you are trying to use the user variable before it has been defined, which is why you get the error.
Here is the correct way to use aliases, from the docs:
cy.fixture('admindetails').as('usersJSON')
cy.route('GET', '/users/**', '#usersJSON') // or another command that supports aliasing
Your first test case is also fine to use as well, if you need the fixture contents later on they will be stored as user:
cy.fixture('admindetails').then((user) => {
cy.log(user.username)
/** add any other test code that needs `user` here **/
})
/** write the rest of your tests here, they will execute after the .then block **/
Related
I'm learning Vue2 and currently, I have a simple boilerplate using Laravel, Vue2, Laravel Echo, Sanctum, and the Websockets package, all using the Laravel default Echo setup. Everything works nicely there.
Now I'm trying to decouple things, so I've created the same boilerplate but as a Vue SPA and using Laravel Passport (I have my reasons for decoupling things and for using Passport). Everything works fine there as well, including a timeline I've added, but not the real-time stuff.
I need to pass the user id with the Echo event in a few places, so I created a global user object in main.js, like this (I'm using namespaced modules):
let User = store.state.auth.user
Vue.prototype.$user = User
But every time I try passing the user id to an event, the id is undefined, so Pusher cannot authenticate the channel. Though if I console log the user from within any component, I can see the user object with the id. I can also see the event in the Websockets dashboard. So everything works as normal, except passing the id. If I do this:
Echo.private(`timeline.${this.$user.id}`)
.listen('.PostWasCreated', (e) => {
this.PUSH_POSTS([e])
})
The results is this:
private-timeline.undefined
I've also tried other syntax, such as:
Echo.private('timeline.'+this.$user.id)
.listen('.PostWasCreated', (e) => {
this.PUSH_POSTS([e])
})
I'm having a difficult time trying to determine what I'm missing to be able to pass the id.
Try to use a function to defer, instead of an assignment. It is not defined during the assignment.
Vue.prototype.$getUser = ()=>store.state.auth.user
Echo.private(`timeline.${this.$getUser().id}`)
.listen('.PostWasCreated', (e) => {
this.PUSH_POSTS([e])
})
or access the store directly.
Echo.private(`timeline.${this.$store.state.auth.user.id}`)
.listen('.PostWasCreated', (e) => {
this.PUSH_POSTS([e])
})
Or even better, use a getter in your store. (I will leave it to you to add the getter...)
Echo.private(`timeline.${this.$store.getters.userId}`)
.listen('.PostWasCreated', (e) => {
this.PUSH_POSTS([e])
})
I'm trying to test an application with Mocha.
In Mocha I should be able to use the only feature to select a sublist of tests to run, like:
describe.only('my tests', () => {
// my tests...
})
instead of the usual:
describe('my tests', () => {
// my tests...
})
But only returns the compile-time error:
Property 'only' does not exist on type ...
describe and it are well recognized and work fine.
Why is only not recognized? It is part of the official Mocha, is not an extension or similar.
I don't know the cause, but adding this at the beginning solved the problem:
import { it, describe } from 'mocha'
Now I'm able to compile the TypeScript code and the tests are executed fine.
Note: don't include only in the imports.
To bind my data on the mobile side it works like this :
getHeros() {
this.wakanda.getCatalog().then(ds => {
ds['Superhero'].query({orderBy:"ID desc",pageSize:3}).then(collection => {
this.favoriteSuperheroes = collection.entities;
});
});
}
But like this I work directly on the table. I have a method who provide me everything I want on the server side. The Wakand's documentation tells me to do it like this:
ds.Company.myDataClassMethod().then(function (result) {
});
It won't work, I can't call my method, someone can help me ?
If the query() on the table works for you while calling dataclasss method does not. A possible cause is that your class method is not set to available to the public.
Please check whether the scope of the class method is set to "public".
And test if your method can be accessed directly via REST:
127.0.0.1:8081/rest/Company/myDataClassMethod
Update: add type "any" to ds solves the problem. It appears
this.wakanda.getCatalog().then(ds:any => {
ds['Company'].myDataClassMethod().then(result => {
//Work with Result Here
});
});
I am trying to use Laravel 4 method called Route:input("users"). But I am getting following error
Call to undefined method Illuminate\Routing\Router::input()
Any idea how Route::input() works. Is there any file I need to change.
Thanks all
Route::filter('userFilter', function () {
if (Route::input('name') == 'John') {
return 'Welcome John.';
}
});
Route::get('user/{name}', array(
'before' => 'userFilter',
function ($name) {
return 'Hello, you are not John.';
}));
It looks as though Route::input was added in Laravel 4.1, make sure this is the version you are working with if you need to use this functionality.
I assume you've read the docs, but since you asked how it works, here's the example:
Accessing A Route Parameter Value
If you need to access a route parameter value outside of a route, you may use the Route::input method:
Route::filter('foo', function()
{
// Do something with Route::input('users');
});
I cant seem to get the Mail Facade to accept a ->with() command for Testing.
This works:
Mail::shouldReceive('send')->once();
But this does not work:
Mail::shouldReceive('send')->with('emails.welcome')->once();
and neither does this:
Mail::shouldReceive('send')->with('emails.welcome', array(), function(){})->once();
and neither does this:
Mail::shouldReceive('send')->with('emails.welcome', array(), function($message){})->once();
All give the following error:
"No matching handler found for Illuminate\Mail\Mailer::send("emails.welcome", Array, Closure)"
So how can I test Mail to check what it is receiving?
Also - for bonus points - is it possible to test what Mail is doing inside the closure? i.e. can I check what $message->to() is set to?
edit: my mail code:
Mail::send("emails.welcome", $data, function($message)
{
$message->to($data['email'], $data['name'])->subject('Welcome!');
});
The code examples below assumes PHP 5.4 or newer - if you're on 5.3 you'll need to add $self = $this before the following code and use ($self) on the first closure, and replace all references to $this inside the closure.
Mocking SwiftMailer
The simplest way is to mock the Swift_Mailer instance. You'll have to read up on what methods exist on the Swift_Message class in order to take full advantage of it.
$mock = Mockery::mock('Swift_Mailer');
$this->app['mailer']->setSwiftMailer($mock);
$mock->shouldReceive('send')->once()
->andReturnUsing(function(\Swift_Message $msg) {
$this->assertEquals('My subject', $msg->getSubject());
$this->assertEquals('foo#bar.com', $msg->getTo());
$this->assertContains('Some string', $msg->getBody());
});
Assertions on closures
Another way to solve this is to run assertions on the closure passed to Mail::send. This does not look all that clean, and its error messages can be rather cryptic, but it works, is very flexible, and the technique can be used for other things as well.
use Mockery as m;
Mail::shouldReceive('send')->once()
->with('view.name', m::on(function($data) {
$this->assertContains('my variable', $data);
return true;
}), m::on(function($closure) {
$message = m::mock('Illuminate\Mailer\Message');
$message->shouldReceive('to')
->with('test#example.com')
->andReturn(m::self());
$message->shouldReceive('subject')
->with('Email subject')
->andReturn(m::self());
$closure($message);
return true;
}));
In this example, I'm running an assertion on the data passed to the view, and I'll get an error from Mockery if the recipient address, subject or view name is wrong.
Mockery::on() allows you to run a closure on a parameter of a mocked method. If it returns false, you'll get the "No matching handler found", but we want to run assertions so we just return true. Mockery::self() allows for chaining of methods.
If at any point you don't care what a certain parameter of a method call is, you can use Mockery::any() to tell Mockery that it accepts anything.