Comments (5)
I'm agree with you it's the solution that i adopted
from ngx-materialize.
Hi @chych, can you provide a sample of your html, component and test code? I'm wondering if the error is related to your test code or to our library ...
from ngx-materialize.
Actually my component is empty, no code except constructor...,
html template just content mz-sidenav component
the problem appear with the [collapseButtonId]="'btnSidenav'" because i split the header and sidenav in two differents component.
My home component contains :
<app-header></app-header>
<app-home-sidenav></app-home-sidenav>
My header template:
<header>
<div class="navbar-fixed navbar-mycj">
<nav class="nav-mycj blue-grey" [ngClass]="{navFixed: navIsFixed}" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="#" class="brand-logo position">
<img alt="logo mycloudjob" src="./assets/images/mycj/logo-navbar.png">
</a>
<ul class="right hide-on-med-and-down">
<li><a href="#" class="btn blue-grey">Se connecter</a></li>
<li><a href="#" class="btn pink">S'inscrire</a></li>
</ul>
<a href="#"
[id]="'btnSidenav'"
class="button-collapse hide-on-large-only right"><i class="material-icons">menu</i></a>
</div>
</nav>
</div>
</header>
My component containing(app-home-sidenav) :
import {Component, OnInit} from "@angular/core";
@Component({
selector: 'app-home-sidenav',
templateUrl: './home-sidenav.component.html',
styleUrls: ['./home-sidenav.component.css']
})
export class HomeSidenavComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
My component html(app-home-sidenav) :
<mz-sidenav
[id]="'sidenav'"
[collapseButtonId]="'btnSidenav'">
<mz-sidenav-header>
Sidenav header
</mz-sidenav-header>
<mz-sidenav-subheader>Link Subheader</mz-sidenav-subheader>
<mz-sidenav-link>
<a href="#">First Link</a>
</mz-sidenav-link>
<!--<mz-sidenav-divider></mz-sidenav-divider>-->
<mz-sidenav-link [active]="true">
<a href="#">Active Link</a>
</mz-sidenav-link>
<mz-sidenav-divider></mz-sidenav-divider>
<mz-sidenav-link>
<a href="#" class="waves-effect">Second Link With Waves</a>
</mz-sidenav-link>
</mz-sidenav>
My component test(app-home-sidenav)
import {async, ComponentFixture, TestBed} from "@angular/core/testing";
import {HomeSidenavComponent} from "./home-sidenav.component";
import {MaterializeModule} from "ng2-materialize";
describe('HomeSidenavComponent', () => {
let component: HomeSidenavComponent;
let fixture: ComponentFixture<HomeSidenavComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
HomeSidenavComponent,
],
imports: [
MaterializeModule,
],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HomeSidenavComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should be created', () => {
expect(component).toBeTruthy();
});
});
from ngx-materialize.
The solution i found it's to not separate my colapse button and the sidenav :
<header>
<div class="navbar-fixed navbar-mycj">
<nav class="nav-mycj blue-grey" [ngClass]="{navFixed: navIsFixed}" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" href="#" class="brand-logo position">
<img alt="logo mycloudjob" src="./assets/images/mycj/logo-navbar.png">
</a>
<ul class="right hide-on-med-and-down">
<li><a href="" class="btn blue-grey">Se connecter</a></li>
<li><a href="" class="btn pink">S'inscrire</a></li>
</ul>
<a href=""
[id]="'btnSidenav'"
class="button-collapse hide-on-large-only right"><i class="material-icons">menu</i></a>
</div>
</nav>
</div>
</header>
<mz-sidenav
[id]="'sidenav'"
[collapseButtonId]="'btnSidenav'">
<mz-sidenav-header>
Sidenav header
</mz-sidenav-header>
<mz-sidenav-subheader>Link Subheader</mz-sidenav-subheader>
<mz-sidenav-link>
<a href="#">First Link</a>
</mz-sidenav-link>
<!--<mz-sidenav-divider></mz-sidenav-divider>-->
<mz-sidenav-link [active]="true">
<a href="#">Active Link</a>
</mz-sidenav-link>
<mz-sidenav-divider></mz-sidenav-divider>
<mz-sidenav-link>
<a href="#" class="waves-effect">Second Link With Waves</a>
</mz-sidenav-link>
</mz-sidenav>
from ngx-materialize.
@chych the reason why your test fails is because it cannot find the provided collapseButtonId
as it does not exist in the context of your test which only include the app-home-sidenav
component.
If you absolutely want to keep them seperated you will need to create a fake collapse button element with the exact same button id in your app-home-sidenav
test file.
function createCollapseButton(id: string): void {
const collapseButton = document.createElement('a');
collapseButton.setAttribute('id', id);
document.body.appendChild(collapseButton);
}
beforeEach(() => {
fixture = TestBed.createComponent(HomeSidenavComponent);
component = fixture.componentInstance;
// create fake collapse button in DOM before triggering
// change detection that initialize the component
createCollapseButton('btnSidenav');
fixture.detectChanges();
});
Although this would work I don't suggest you to seperate the collapse button and the sidenav because your test won't assure you that the button is really there at runtime or is really having the right id.
from ngx-materialize.
Related Issues (20)
- How to make a fixed navbar ? HOT 3
- Ho to align material-icon and a text-input HOT 1
- Tooltip with max width HOT 1
- Components no implements (click)
- autocomplete not working for input if data is dynamically bind through webservice HOT 3
- MzToastService.show: Materialize is not defined HOT 2
- Autocomplete not working with chip input (does with regular input) HOT 1
- Dropdown click inisde elements closes HOT 1
- Errors after updating to Angular 7 HOT 2
- Pagination component.
- Sidenav - this.collapseButton.sideNav is not a function HOT 5
- "Falling" icon in float+flat button in a mz-navbar HOT 1
- Chip selected when scrolling (swiping) through chip autocomplete list.
- Add own picture in select option with data-icon?
- Date picker and Time picker issue in latest chrome browser HOT 15
- Date picker - How Modify default Language HOT 2
- Text area not expanding on large input size HOT 1
- Getting compilation error when import ngx-materialize. HOT 1
- pagination breaks after totalItems = 0 HOT 1
- @angular/core has no exported member 'Renderer' HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-materialize.