Skip to content

Commit

Permalink
test: add tests for Button component (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiobiondi authored Jan 28, 2024
1 parent e525f80 commit b032fd0
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { SfIconHome } from '../SfIcons';
import { SfButton } from './SfButton';

it('should render content', () => {
const content = 'label';
cy.mount(<SfButton>{content}</SfButton>);
cy.contains(content).should('be.visible');
});

it('should render an anchor', () => {
cy.mount(
<SfButton as="a" href="/">
Link
</SfButton>
);
cy.get('a').should('have.attr', 'href', '/');
});

it('should display prefix content', () => {
cy.mount(
<SfButton slotPrefix>
<div q:slot="prefix"></div>
Home
</SfButton>
);

cy.get('button')
.invoke('text')
.should((text) => {
const regex = /\s*Home/;
expect(regex.test(text)).to.be.true;
});
});

it('should display suffix content', () => {
cy.mount(
<SfButton slotSuffix>
<div q:slot="suffix"></div>
Home
</SfButton>
);

cy.get('button')
.invoke('text')
.should((text) => {
const regex = /Home\s*/;
expect(regex.test(text)).to.be.true;
});
});

0 comments on commit b032fd0

Please sign in to comment.