During the Cold War, the United States and the Soviet Union made a habit of testing their nuclear weapons on land, sea, in the air and under the ground. While these tests were justified as having scientific purpose, the two nations benefitted from the propaganda value of testing bombs and missiles that could obliterate their enemies (ie. each other).
One of the more bizarre chapters of this rivalry was that of nuclear weapons tested in space. Once the United States and Soviet Union proved they could fire nuclear missiles at each other from thousands of kilometres away, they found themselves having to experiment with ways of shooting their enemies’ missiles down. Precision guidance systems didn’t exist, so the solution was to simply use massive explosions to knock the missiles out of the game.
Between 1958 and 1962, there were 17 nuclear tests ranging from an altitude of 22.7 kilometres (14.1 miles) to 540 kilometres (335.5 miles) above the Earth. The largest explosion was that of the Starfish Prime test. A W49 thermonuclear warhead detonated at an altitude of 400 kilometres (250 miles) with a force of 1.4 megatons of TNT. The result was the creation of an artificial radiation belt in space which destroyed three satellites, while the electromagnetic pulse of the explosion damaged electronic systems over a thousand kilometres away.
The Soviets experienced similar problems with their space testing program, with power and communcations systems being crippled.
Consequently, the tests ended. They worked too effectively and posed a threat to manned space exploration.
Short answer: Nuclear weapon tests in space were conducted in the 1950s and 1960s, but were discontinued because they caused too much damage.