- Create a component
- Create a corresponding service
- Add properties and methods to the service
- Ask for the service to be injected into the component as a dependency:
do this by specifying it as a property in the signature of the
component's constructor
- If there's need to access this service outside the component, for example, in a template, then specify a public property
| <!DOCTYPE html> | |
| <html class="no-js" lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <title>inQubate</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
| <meta name="" content=""> | |
| <meta name="author" content="Mfon Eti-mfon"> | |
| <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Charm|Montserrat:300&display=swap"> |
| // App | |
| import { Component } from '@angular/core'; | |
| @Component({ | |
| selector: 'app', | |
| template: '<span>{{ sayHello() }}</span>', | |
| }) | |
| export class App { | |
| public name: string = 'John'; |
| import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | |
| import { TestBed, async, inject } from '@angular/core/testing'; | |
| import { PostService } from './post.service'; | |
| describe('PostService', () => { | |
| // before this entire suite of unit tests is run | |
| // declare the http mock and the service to be tested |
Final implementation of Implementing JSON Web Token (JWT) to secure your app.
axios
The aiohttp_client fixtures from pytest_aiohttp was (and still is) an excellent idea. The promise I saw in it was that I would be able to run my tests the way I do while working with Django. That is, the test runner will automatically run the app for the duration of the tests, a db will be created specifically for the tests, and the tests will be run in isolation with respect to each other.
However, this did not work out so well for me. aiohttp_client kept erroring out with a warning that the event loop was already in use.
In attempting to solve this problem, I learnt how to create a session-scoped event loop for tests - the default loop exposed by pytest_asyncio is function scoped, and a number of the fixtures I had created at that iteration of the app were session scoped and required a session scoped event loop.
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Tabbed Page</title> | |
| <link rel="stylesheet" type="text/css" href="styles.css"> | |
| </head> | |
| <body> | |
| <main> | |
| <section class="red"></section> | |
| <section class="orange"></section> |
Open file with vim
$ sudo vim <filename>
Press i to go into edit mode
Edit the file
| import datetime | |
| import json | |
| from typing import Dict, List, Optional | |
| from requests import Request, Response, Session | |
| from requests_mock import Adapter | |
| from requests_mock.request import _RequestObjectProxy | |
| adapter = Adapter() | |
| session = Session() |
| Microsoft Windows [Version 10.0.19041.508] | |
| (c) 2020 Microsoft Corporation. All rights reserved. | |
| C:\Users\Mfonism>python --version | |
| Python 3.8.1 | |
| C:\Users\Mfonism>python -c "import sys; print(sys.executable)" | |
| C:\Users\Mfonism\AppData\Local\Programs\Python\Python38\python.exe | |
| C:\Users\Mfonism>python -m pip install -U pip |