A map $f:X\to Y$ of unpointed spaces is a weak homotopy equivalence if and only if for every CW space $K$ the map $[K,X]\to [K,Y]$ induced by $f$ is a bijection. In particular this implies that if $X$ and $Y$ are themselves CW spaces (or homotopy equivalent to such) then $f$ must be a homotopy equivalence.
It might not be a bad idea to take the above as a definition of "weak homotopy equivalence", but the usual thing is to say instead that $f$ is a weak homotopy equivalence if (1) it induces a bijection $\pi_0(X)\to \pi_0(Y)$ of sets of path-components, and (2) for every $n>0$ and every point $x\in X$ (or equivalently for at least one point in every path-component) it induces an isomorphism $\pi_n(X,x)\to \pi_n(Y,f(x))$.
The latter condition is much easier to check, of course, but I'm with you: the former is a more appealing definition in a way.
The fact that the latter condition implies the former is somewhat nontrivial. Even the fact that the former implies the latter is a little bit nontrivial, since the one uses unpointed maps while the other uses pointed maps of spheres.
Curiously, it is possible for a map $X\to Y$ to induce bijections $[S^n,X]\to [S^n,Y]$ for all $n$ without being a weak homotopy equivalence: you just have to come up with a group homomorphism $G\to H$ that induces a bijection on conjugacy classes but is not an isomorphism, and then let $X$ and $Y$ be corresponding Eilenberg-MacLane spaces.
And it should also be noted that a map $X\to Y$ need not be a weak homotopy equivalence if it induces bijections $[(K,k),(X,x)]\to [(K,k),(Y,f(x)]$ for every pointed $K$ and every choice of $x\in X$: this definition lets you down, for example, if $X$ is empty.
Finally, if you are specifically interested in pointed spaces (but not necessarily path-connected) then the generally agreed upon definition is that a pointed map $(X,x)\to (Y,y)$ is a weak homotopy equivalence if the unpointed map $X\to Y$ is a weak homotopy equivalence. So the maps $\pi_n(X,x)\to \pi_n(Y,y)$ being isomorphisms, even including $n=0$, is not enough.