This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: "app-user-list", | |
templateUrl: "./user-list.component.html", | |
styleUrls: ["./user-list.component.css"], | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class UserListComponent { | |
@Input() | |
users: User[]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<app-user-list [users]="users$ | async"></app-user-list> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class DashboardComponent implements OnInit { | |
users$: Observable<User[]>; | |
constructor(private userService: UserService) {} | |
ngOnInit() { | |
this.users$ = this.userService.users$; | |
this.userService.getAll(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class UserService { | |
private musers$ = new BehaviorSubject<User[]>([]); | |
get users$(): Observable<any[]> { | |
return this.musers$.asObservable(); | |
} | |
constructor(private httpClient: HttpClient) {} | |
getAll() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cy.server(); | |
// create aliases | |
cy.route("activities/*", "fixture:activities").as("getActivities"); | |
cy.route("messages/*", "fixture:messages").as("getMessages"); | |
// visit the dashboard, which should make requests that match | |
// the two routes above | |
cy.visit("http://localhost:8888/dashboard"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cy.server(); | |
// we set the response to be the activites.json fixture | |
cy.route("GET", "users/*", "fixture:users.json"); | |
//or | |
cy.fixture("users.json").as("usersJSON"); // alias the fixture | |
cy.route("GET", "users/*", "@usersJSON"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cy.server(); // start the server | |
cy.route({ | |
method: "GET", // Route all GET requests | |
url: "/users/*", // that have a URL that matches '/users/*' | |
response: [] // and force the response to be: [] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("The Home Page", function() { | |
beforeEach(() => { | |
cy.visit("/"); | |
}); | |
it("h2 should have proper text", () => { | |
// https://on.cypress.io/within | |
cy.get("h2:first").should( | |
"have.text", | |
"Here are some links to help you start: " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beforeEach(() => { | |
cy.visit('https://example.cypress.io/commands/actions') | |
}); | |
it('.within() - query DOM elements within a specific element', () => { | |
// https://on.cypress.io/within | |
cy.get('.query-form').within(() => { | |
cy.get('input:first').should('have.attr', 'placeholder', 'Email') | |
cy.get('input:last').should('have.attr', 'placeholder', 'Password') | |
}) |