
Security News
Cline CLI npm Package Compromised via Suspected Cache Poisoning Attack
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.
ngx-testing-library
Advanced tools
Lightweight utility functions to test Angular components.
Install ngx-testing-library from npm and add it your devDependencies:
npm install ngx-testing-library --save-dev
ngx-testing-library is an Angular adapter around dom-testing-library, which provides lightweight ulitity functions to test UI components. Your tests will work with actual DOM nodes.
createComponentThis library only consists of one function, createComponent which is used to setup the Angular TestBed and creates the component fixture.
This method can be used in two ways:
Based on a template:
import { createComponent } from 'ngx-testing-library';
createComponent('<my-component [prop]="1"></my-component>', options);
Based on a component type:
import { createComponent } from 'ngx-testing-library';
createComponent(
{
component: MyComponent,
parameters: {
prop: 1,
},
},
options,
);
The second parameter in createComponent is the options parameter, which looks like this:
{
detectChanges?: boolean = true;
declarations: any[] = [];
providers?: any[] = [];
imports?: any[] = [];
schemas?: any[] = [];
}
detectChanges: runs detectChanges on the fixture
declarations: passed to the TestBed
providers: passed to the TestBed
imports: passed to the TestBed
schemas: passed to the TestBed
The createComponent function returns an object consisting all of the query functions from dom-testing-library and adds the following properties:
container: HTMLElementThe DOM node containing the Angular component.
All of the dom-testing-library query functions are binded to this container.
debug() => voidPrints out the container.
detectChanges(checkNoChanges?: boolean) => voidRuns detectChanges on the fixture.
fixture: anyThe Angular fixture.
getFromTestBed(token: any, notFoundValue?: any) => anyCalls the the Angular TestBed.get function.
getComponentInstance(selector?: string) => TGets the Angular component instance.
The selector is required when the template syntax is being used, in order to get the component.
fireEventExposes the fireEvent from dom-testing-library.
import { fireEvent } from 'ngx-testing-library';
fireEvent.click(buttonNode);
You can find some examples in the tests folder.
Here is how "default" specifications are written with ngx-testing-library.
Before:
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
}).compileComponents();
}));
it(`should have as title 'my-awesome-app'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('my-awesome-app');
}));
it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to my-awesome-app!');
}));
});
After:
import { AppComponent } from './app.component';
import { createComponent } from 'ngx-testing-library';
it(`should have as title 'my-awesome-app'`, async () => {
const { detectChanges, getByText } = await createComponent('<app-root></app-root>', {
declarations: [AppComponent],
});
expect(getByText('Welcome to my-awesome-app!')).toBeDefined();
});
it(`should render title in a h1 tag`, async () => {
const { container } = await createComponent(
{
component: AppComponent,
},
{
declarations: [AppComponent],
},
);
expect(container.querySelector('h1').textContent).toContain('Welcome to my-awesome-app!');
});
MIT
FAQs
Test your Angular components with the dom-testing-library
The npm package ngx-testing-library receives a total of 18 weekly downloads. As such, ngx-testing-library popularity was classified as not popular.
We found that ngx-testing-library demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.

Product
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.