npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

testing-a11y

v0.2.0

Published

<h2 align="center">testing-a11y</h2>

Downloads

13

Readme

Example

You have a component that you'd like to write integration tests for in the simulator using something like appium or detox.

You've added accessibility, and platform specific code. It's alot to remember for each place you'd like an ID, or just some a11y text.

import * as React from "react";
import { Text } from "react-native";

export const testID = "amount";
const isTesting = () => global.TEST_MODE === true;

export default () => (
  <>
    <Text>Label</Text>
    <Text
      testID={testID}
      accessible={true}
      accessibilityLabel={isTesting() ? testID : "The price of the item"}
    >
      £50.00
    </Text>
  </>
);

That's a load of juggling for every component

Enter testing-a11y!

import * as React from "react";
import { Text } from "react-native";
import { a11yLabel, a11yOf, a11yProps } from "./lib/testID";

export const amountID = a11yOf("amount", "The price of the item");

export default () => (
  <>
    <Text>Label</Text>
    <Text {...amountID.asProps()}>£50.00</Text>
  </>
);

Much simpler! The library takes care of the platform/ a11y switching for you, and allows you to store one reference for testID and a11yLabels in a single place.

Want a unique id for an item in a list? testing-a11y can do that too, simply call amountID(ix) instead of passing it:

import * as React from "react";
import { Text } from "react-native";
import { a11yLabel, a11yOf } from "./lib/testID";

export const amountID = a11yOf("amount", "The price of the item");

export default (props) => (
  <>
    {props.items.map((item, ix) => {
      return (
        <Text>{item.name}</Text>
        <Text {...amountID(ix).asProps()}>{item.amount}</Text>
      )
    })}
  </>
);

Imagine you have a common component used all over your app. Each time you use it, because you want it to be easily selectable, you end up passing a differentiating string through to the component to add to the test.

testing-a11y simplifies this by allowing you to wrap components. Everything inside the wrapper will have the prefix added to it's testID!

import * as React from "react";
import { Text, Button } from "react-native";
import { a11yLabel, a11yOf } from "./lib/testID";

export const submitButtonID = a11yOf("SubmitButton");

export const SubmitButton: React.SFC<{}> = (props) => {
  return (
    <Button
      title={"Submit"}
      onPress={() => void 0}
      {...submitButtonID().asProps()}
    />
  );
};

export default (props) => (
  <>
    <TestIDPrefix value="Form">
      <TestIDPrefix value="InnerForm">
        <SubmitButton />
      </TestIDPrefix>
    </TestIDPrefix>
    <TestIDPrefix value="DifferentForm">
      <SubmitButton />
    </TestIDPrefix>
  </>
);

You can now select the two different buttons with:

import { a11yProps } from "testing-a11y";

const firstButton = submitButtonID("Form.InnerForm").asTestID();
const otherButton = submitButtonID("DifferentForm").asTestID();

Much cleaner!